In Yii crud, I've setup a Model, View, and Controller based on my db table called Form. I've modified the controller and views to my liking thus far:
index.php/form/all (index)
index.php/form/new (create)
index.php/form/2 (view)
index.php/form/2/edit (edit)
index.php/form/2/delete (delete)
Now I'd like to setup some subpages that will be dynamic. The url patterns are below. How do I set this up inside of the FormController.php?
index.php/form/2/fields/all
index.php/form/2/fields/new
index.php/form/2/fields/1/edit
index.php/form/2/fields/1/delete
BTW - Fields is a separate db table with a separate yii model. Though I'd like to not create a controller for it if I don't need to.
Thanks Neophile, I ended up adding a fields controller. Here is a link to my finished solution: Yii URLManager rule for multiple controller action parameters
Related
i am using OctoberCMS for a project and in the backend, i want to know how to override the create, update, delete actions in the controller.
Actually, i developed a custom form widget which is a full page calender and i want to use the deffered binding as the model i am trying to save this calender is not exists at the point of creation.
So, any help regarding "Deffered Binding" or "Controller Actions Override" would be appreciated.
I refered the documenation but its not much helpful.
Thanks
You can use your own logic for the create, update or preview action method in the controller, then optionally call the Form behavior parent method
check this link:
https://octobercms.com/docs/backend/forms#overriding-action
I want to have a controller to do some initial settings and fetch some basic data in all of my application pages (written with PHP and CodeIgniter). As I'm new in CI, please help me to do it.
Some of my goals to have such controller:
Setup submenus (regardless of the current page)
Check user login status.
Notice:
I don't have any problem on creating and working with general Controllers in CI. What I need is something like a hidden controller that does not any need to URI segments to run, and it is not the CI default controller too.
What you can do is create a base controller and and extend that base controller in every other controllers instead of CI_Controller. Your base controller will extend CI_Controller. You can add your required checks in the constructor of the base controller and do stuffs according to that. So every time you call a controller your checks will be done. But you have autoload the base controller. I hope this helps you.
I am working in CakePHP for the 1st time. I need to create multiple views for a single controller.
Eg: I have a settings table.
Schema of settings table
1.ID
2.Name
3.Type
I have created its model and controller using cake bake. But i have multiple views from where the data goes into the settings table. My data of designations, departments, qualifications, projects and many other things go into the type field of the settings table with their names as entered.
So when i m creating the model and controller thru cake bake it is creating view as per the settings table, whereas i need view pages as per types, i.e Create Designation, Create Departments, Create Projects and also view, edit and delete files for them.
Pls help me find a way to achieve that..
I think you are looking for
$this->render('viewfilename');
create as many views as you want and based on your requirement send then in specific view from controller.
For example:
public function add($type) {
if ($this->request->is('post')) {
...
}
$this->set(............);
switch ($type) {
case 'designations':
$this->render('add_designations');
break;
case 'departments':
$this->render('add_departments');
break;
case 'qualifications':
$this->render('add_qualifications');
break;
}
}
and make view files as add_designations.ctp, add_departments.ctp, add_qualifications.ctp etc in view folder.
You can add Views by creating a .ctp file in the respective Views Folder (Views/"Modelname"/add_department.ctp)
In your "Modelname" Controller you just add
function addDepartment() {
// Logic here
}
But if you just want to set the type, you can create a normal add.ctp and create a Selectbox with all the different possible Types.
You need to read again how the pattern Model View Controller (MVC) works.
If you want to create a new department, you probably want to use the departmentsController associated with the Department model.
In each controller you will have the actions associated with it. This way Cake Bake will generate the add, delete and edit code for each of your controllers.
Of course, you can create them by your own in the controller you prefer making use of the model you wish. But don't expect Cake bake to work differently :)
You have the URL:
http:///www.site.com/controller/method/values/1/2/3
Do I have to always have the controller being called or can I have the view being called and instantiate the controller inside the view or in a bootstrap file referring to this view?
What I don't get it is if I need more than 1 controller on the view, how to archive that?
For example:
On my index page I want run a simple CMS, where the admin can change the text blocks and images of the site. That would be on the content management controller.
On my index page I also got the latest added products vitrine, what would be controlled by the controller products.
If I define www.site.com/contentmanagement or www.site.com to run the contentmanagement controller, how the product controller would be called?
Also, another example. On my menu I got a link to a page called aboutus, that would be a simple page and the only feature needed would be the content management controller to manage the texts blocks.
If I follow the pattern Im reading all over the place I will end with a link like:
http://www.site.com/contentmanagement/method/aboutus
?
Kinda lost here cause surely this URL will look weird. Would be much easier to have the URL calling the view http://www.site.com/aboutus and a boot file where I can tell the controller that should be loaded when the surfer is there ...
bootstrap would look like:
switch($view)
case: index
controller load contentmanagement
controller load product
case: aboutus
controller load contentmanagement
I appreciate any help or a light here, thanks.
by the way, Im coding in PHP.
Hm, if you want to have text blocks and images of the site (one controller), and products vitrine (second controller), then call the methods you need in one controller..
I would do it this way: when you request index page with all the elements you mentioned above, actually one controller is called, and it decides which view to show.. so in that controller, you call the all methods that you need, get the data, and pass it to the view.. if the methods are called from other controllers, just call that methods and get the data.. i often make some static methods in controllers, which I can call anywhere, so I don't have to instantiate whole object..
E.g. you call www.site.com/contentmanagement, controller is called, which will display index view, and in that controller, you call all methods you need, prepare the data, and pass that data to the final view which will be displayed..
Do I have to always have the controller being called or can I have (..blah blah..)?
It kinda depends on what you understand by "call".
Controller needs an ability to change state of both View and Model(s).
And each View need ability to request data (in Model2 MVC) from Model(s).
Thought Controller should not cause the rendering of View (which is common in all the RoR sycophants) much like View has not business in executing actions on the Controller.
What I don't get it is if I need more than 1 controller on the view, how to archive that?
Views and Controllers should have 1:1 relationship. If your view need more then one controller, you might want to look into HMVC architecture.
For example: On my index page I want run a simple CMS, (.. more blah .. ) how the product controller would be called?
CMS should be a separate application ( or at least module ) with multiple controllers.
If I follow the pattern Im reading all over the place I will end with a link like: http://www.site.com/contentmanagement/method/aboutus ?
Why not just http://site.com/cms/content/2/edit (where 2 is the ID for "about us" page). There is no law which states that URL structure for site administration must mirror the publicly available page .. hell .. it can actually cause increased vulnerability.
I am going to try to walk
What I don't get it is if I need more than 1 controller on the view,
how to archive that?
For example: On my index page I want run a simple CMS, where the admin
can change the text blocks and images of the site. That would be on
the content management controller. On my index page I also got the
latest added products vitrine, what would be controlled by the
controller products. If I define www.site.com/contentmanagement or
www.site.com to run the contentmanagement controller, how the product
controller would be called?
Having the URL to contains the controller's name is definitely nice, but it is not the requirement for MVC. So you don't have to necessary map your controller to the URL itself. A classic MVC does not tie itself to a particular naming convention, so you could call your product controller via different URL which then process the product and show the view for the product.The important for MVC is to have one controller that deals with sets of model and resulting in one view as the presentation layer. In your particular example, your entry point seems to be a single controller that interacts with both ContentManagement and Product Class/Module and the resulting interaction produce a single view.
bootstrap would look like:
switch($view)
case: index
controller load contentmanagement
controller load product
case: aboutus
controller load contentmanagement
Thus your original interaction above is not completely off, except that you are not really calling two controllers, but rather doing the following upon hitting index:
Load a controller, let's call this one IndexController
Load ContentManagement module to get the related content, you might want to put the info as part of your Model for the Index page
Load Product module to get related products, again put this into your Model
Pass the Model containing the info for rendering the page into the View
In your View, you render the Model that contains both Content from ContentManagement module and Product list from the Product module thereby producing a single view
If I follow the pattern Im reading all over the place I will end with
a link like: http://www.site.com/contentmanagement/method/aboutus ?
This is again not a requirement, you should follow what makes sense and easier for the users. Also, if you are required to follow the conventions, you could always make your URL pretty by using URL mapping.
What you are looking for is called HMVC and there are a couple of frameworks for that out there, like Kohana.
Also see this question:
What is the HMVC pattern?
In zend framework, how do i create an action for this type of url:
example.com/admin/create/category
which would show a page for creating a new category
or
example.com/admin/edit/category/id
which would show a page to edit a category
here, admin would be the controller, create and edit would be the action but what about the last parameter 'category'? should i check for 'category' argument inside the controller actions or is there another way ?
thanks
Having this kind of issue, I suggest using zend route. Here's the link
http://framework.zend.com/manual/en/zend.controller.router.html
You can create multiple routes for each action if needed.
I think that the good way is to check for 'category' argument inside the controller actions. Based on its value you do what you want.
Assuming you have lots of different "things" you need to administer then i woudl suggest not using ana single admin controller but rather a Category controller. Then just secure the admin actions. Alternatively you sould have 2 controllers a Category controller and an AdminCategory controller...But either way you should have multiple controllers for the admin module....
Also keep in mind you can set up routes pretty much however you like... not every segment in the url needs to map to a parameter...