Yii2 访问新控制器中的操作
Yii2 access to actions in new controllers
同志们,我在实现 yii2 basic 时遇到了问题,但我还没有放弃。我已经成功安装了 yii2,激活了 pretty url 并在根文件夹中创建了 .htaccess 文件。主页、关于、联系和登录 url 工作正常。
我。我用 CRUD 创建了一个新模型 InstTypes。为什么找不到 http://localhost:8081/we@ss/instTypes/create return (#404)?
二。我还创建了一个模块 instClients。我可以访问 DefaultControler 中的索引操作。我在这个模块下有一个带有 CRUD 的模型 Insts。为什么找不到 http://localhost:8081/we@ss/instClients/insts/create return (#404)?
我倾向于认为这可能是由于从配置中删除了导入和自动加载。
有人可以演示他们如何创建新模型和 CRUD 并成功访问其操作吗?
提前致谢
I have created a new model, InstTypes with the CRUD. Why does
http://localhost:8081/we@ss/instTypes/create return Not Found (#404)?
您不能直接访问模型,与模型交互的唯一方法是通过控制器,它将与模型和视图进行交互。通过初始化模型 $model = new YourModelNmae();或通过渲染视图。
来自您的 URL
InstType 应该是您的控制器,而创建是 InstType 下的一个动作
使用 Yii2 Gii 工具生成 CRUD 执行以下操作:-
- 生成模型
- 生成您的 CRUD
转到
http://localhost:8081/we@ss/yourController/YourActionOnYourController
请参阅此 youtube link 了解更多详情 https://www.youtube.com/watch?v=6B52-li6IgU
编码愉快 :)
this 解决了我的问题。我需要将控制器添加到控制器映射中。
补充一下其他答案,您的 url 不工作,因为它是驼峰式。你需要让它连字符,所以
http://localhost:8081/we@ss/instTypes/create
会变成
http://localhost:8081/we@ss/inst-types/create
您收到 404 是因为您正在尝试访问 instTypes,它应该是 inst-types。
同志们,我在实现 yii2 basic 时遇到了问题,但我还没有放弃。我已经成功安装了 yii2,激活了 pretty url 并在根文件夹中创建了 .htaccess 文件。主页、关于、联系和登录 url 工作正常。
我。我用 CRUD 创建了一个新模型 InstTypes。为什么找不到 http://localhost:8081/we@ss/instTypes/create return (#404)?
二。我还创建了一个模块 instClients。我可以访问 DefaultControler 中的索引操作。我在这个模块下有一个带有 CRUD 的模型 Insts。为什么找不到 http://localhost:8081/we@ss/instClients/insts/create return (#404)?
我倾向于认为这可能是由于从配置中删除了导入和自动加载。
有人可以演示他们如何创建新模型和 CRUD 并成功访问其操作吗?
提前致谢
I have created a new model, InstTypes with the CRUD. Why does http://localhost:8081/we@ss/instTypes/create return Not Found (#404)?
您不能直接访问模型,与模型交互的唯一方法是通过控制器,它将与模型和视图进行交互。通过初始化模型 $model = new YourModelNmae();或通过渲染视图。
来自您的 URL
InstType 应该是您的控制器,而创建是 InstType 下的一个动作
使用 Yii2 Gii 工具生成 CRUD 执行以下操作:-
- 生成模型
- 生成您的 CRUD
转到
http://localhost:8081/we@ss/yourController/YourActionOnYourController
请参阅此 youtube link 了解更多详情 https://www.youtube.com/watch?v=6B52-li6IgU
编码愉快 :)
this 解决了我的问题。我需要将控制器添加到控制器映射中。
补充一下其他答案,您的 url 不工作,因为它是驼峰式。你需要让它连字符,所以
http://localhost:8081/we@ss/instTypes/create
会变成
http://localhost:8081/we@ss/inst-types/create
您收到 404 是因为您正在尝试访问 instTypes,它应该是 inst-types。