since I am fairly new to CakePhp and since my research has not yielded any definitive results concerning my specific problem so far, I figured the best thing to do would be to ask here. :) Bear with me, this is going to be rather elaborate, I fear...
I'm creating an application with CakePhp (2.1) and Javascript / JQuery, one basic functionality is that table entries can be viewed in different ways, to which I will come in a moment. My main content area consists of 2 sub divisions, one is the actual main content, the other is a horizontally sliding area which can be toggled on and off (in the following text referred to as "accordion"). I will attach an image at the end of the post to exemplify what I mean.
The afore mentioned different views ( / edits / adds) are:
*1. Standard view* would be in accordion which is hidden until a table entry is chosen, once the view is triggered, the area is supposed to slide from the right side into the screen and overlap the underlying table, the area can be toggled on and off. Basically it acts as a horizontal accordion window, the user is able to quickly manipulate table entries, hide the entry to look something up in the table, and show the entry again to continue whatever he was doing before. *2. Fullscreen view *is supposed to be rendered in the actual main content area, in this view the table is transferred to the accordion, basically table and table entry swap positions.
Another aspect of the application is that table entries can be stored in "favourites" or "clipboard", those two are small windows which can be shown on any page of the application and which are also part of the start page.
Now that I have started to try to implement this layout, I have encountered some problems, which might result from me being a beginner in CakePhp. After baking controllers and models via the console, I created the index view for one controller ("companies") and went on to the "add" view for this controller. Naive as I was I simply put the generated "add" view code in the accordion div and left the table (index view) code in the main area div which led to errors. So if I understand this correctly, I cannot simply fill 2 divs with different view contents from only one query, which makes sense. My research led me to the "elements" functionality of cake, though I could only find the cookbook entry for 1.3 ( http://book.cakephp.org/1.3/view/1081/Elements ). Please tell me whether this will help me with my problem, or if there is a better, simple solution for what I am trying to do. (I might have to fill not only the accordion and the main content area with data entries, but also the "favourites" and "clipboard" area once the user clicks the button to show those). I also searched for a way to "fetch" multiple content in my default layout like
but I did not find anything. So this is my first issue. A second one: When the user clicks on a table entry in the table, an option menu is shown at the mouse position from which the user can choose to edit, delete or view the clicked entry. This option menu is also shown when the user clicks on an entry in the favourites or clipboard area. Is there a way to combine PHP and Javascript to determine, which kind of data is clicked (e.g. which controller must be used)? And furthermore, is there a way to integrate (cake)php in code in javascript?
Instead of window.location.href="companyEdit.html"; the cakephp edit view for the correct controller should be triggered.
*Breathes deeply* Excuse my excessive question, but I just started with CakePhp (did research, went through the blog tutorial - which as far as I can tell does not cover what I need for my application), maybe I even missed some CakePhp functionalities which provide exactly what I am looking for.
To sum it up: *1. Multiple Views on one page: *How does one for example show the index view AND the view of one entry of a controller on a single page with CakePhp. *2. Javascript and CakePhp: *How do you use CakePhp view "calls" in javascript, is this even possible, how would one approach the above problem with the option menu (if there is any way apart from separate option menus for all pages AND for "favourites" and "clipboard").
If you have read all the above - Thank you very much! I would have put this in caps but that is just hurting for the eyes. I hope someone can help me and put me on the right way to what I am trying to do :)
I will try to help with the view issue. First look at the 2.x View Template section http://book.cakephp.org/2.0/en/views.html And look into Extending Views. This will allow you to break up the view. You create a frame work for a controller, then the view can have different content in the main section depending on the function.
I would then look at each of these areas that slide in and out might be a good fit for an Element. (see same doc page). You can pass parameters to them to customize them. I use elements for addresses. I have shipping, billing & other address. It formats the address. I pass a title to element to be displayed by element.
you can use the requestAction function in the Elements to get data from another controller function. See sample code in same documentation page under elements.
This way you have a few main functions and views to go with them. Then you have the elements, that may use other functions in the controller or possibly other controllers, to get data. You could do this for a dashboard, or to fill these slide outs that you describe.
You may want to consider adding a Helper to get some of this data for the view, if you think you may want the data on multiple views. The helper can make calls via requestAction to this controller, or possibly other controllers to get some data, that can be formatted by the elements for the view.
> since I am fairly new to CakePhp and since my research has not yielded > any definitive results concerning my specific problem so far, I > figured the best thing to do would be to ask here. :) > Bear with me, this is going to be rather elaborate, I fear...
> I'm creating an application with CakePhp (2.1) and Javascript / > JQuery, one basic functionality is that table entries can be viewed in > different ways, to which I will come in a moment. My main content area > consists of 2 sub divisions, one is the actual main content, the other > is a horizontally sliding area which can be toggled on and off (in the > following text referred to as "accordion"). I will attach an image at > the end of the post to exemplify what I mean.
> The afore mentioned different views ( / edits / adds) are:
> *1. Standard view* would be in accordion which is hidden until a table > entry is chosen, once the view is triggered, the area is supposed to > slide from the right side into the screen and overlap the underlying > table, the area can be toggled on and off. Basically it acts as a > horizontal accordion window, the user is able to quickly manipulate > table entries, hide the entry to look something up in the table, and > show the entry again to continue whatever he was doing before. > *2. Fullscreen view *is supposed to be rendered in the actual main > content area, in this view the table is transferred to the accordion, > basically table and table entry swap positions.
> Another aspect of the application is that table entries can be stored > in "favourites" or "clipboard", those two are small windows which can > be shown on any page of the application and which are also part of the > start page.
> Now that I have started to try to implement this layout, I have > encountered some problems, which might result from me being a beginner > in CakePhp. After baking controllers and models via the console, I > created the index view for one controller ("companies") and went on to > the "add" view for this controller. Naive as I was I simply put the > generated "add" view code in the accordion div and left the table > (index view) code in the main area div which led to errors. So if I > understand this correctly, I cannot simply fill 2 divs with different > view contents from only one query, which makes sense. My research led > me to the "elements" functionality of cake, though I could only find > the cookbook entry for 1.3 ( > http://book.cakephp.org/1.3/view/1081/Elements ). > Please tell me whether this will help me with my problem, or if there > is a better, simple solution for what I am trying to do. (I might have > to fill not only the accordion and the main content area with data > entries, but also the "favourites" and "clipboard" area once the user > clicks the button to show those). I also searched for a way to "fetch" > multiple content in my default layout like
> but I did not find anything. So this is my first issue. A second one: > When the user clicks on a table entry in the table, an option menu is > shown at the mouse position from which the user can choose to edit, > delete or view the clicked entry. This option menu is also shown when > the user clicks on an entry in the favourites or clipboard area. Is > there a way to combine PHP and Javascript to determine, which kind of > data is clicked (e.g. which controller must be used)? > And furthermore, is there a way to integrate (cake)php in code in > javascript?
> Instead of window.location.href="companyEdit.html"; the cakephp edit > view for the correct controller should be triggered.
> *Breathes deeply* Excuse my excessive question, but I just started > with CakePhp (did research, went through the blog tutorial - which as > far as I can tell does not cover what I need for my application), > maybe I even missed some CakePhp functionalities which provide exactly > what I am looking for.
> To sum it up: > *1. Multiple Views on one page: *How does one for example show the > index view AND the view of one entry of a controller on a single page > with CakePhp. > *2. Javascript and CakePhp: *How do you use CakePhp view "calls" in > javascript, is this even possible, how would one approach the above > problem with the option menu (if there is any way apart from separate > option menus for all pages AND for "favourites" and "clipboard").
> If you have read all the above - Thank you very much! I would have put > this in caps but that is just hurting for the eyes. I hope someone can > help me and put me on the right way to what I am trying to do :)
> -- > Our newest site for the community: CakePHP Video Tutorials > http://tv.cakephp.org > Check out the new CakePHP Questions site http://ask.cakephp.org and > help others with their CakePHP related questions.
> To unsubscribe from this group, send email to > [hidden email] </user/SendEmail.jtp?type=node&node=5646347&i=0> For > more options, visit this group at http://groups.google.com/group/cake-php
I see how elements can be used for what I am trying to do. I tried the simple example from the link you provided, so now I can populate multiple ares of one page with different views - that's great!
What I don't quite grasp is the usefulness of adding a helper as you mentioned in your last paragraph. So basically the helper would get all the data for my elements instead of me calling requestAction multiple times?
I was told that AJAX can be used to put content into element areas (via requestAction, too?), e.g. I have my slideout visible which shows a data entry, then, with my table still visible in the main content area, I choose edit on a different entry and instead of loading the page anew, the slideout element loads new content. How would one go about this task? A simple example would be enough to get me started, since I cannot find any useful ones, e.g. a button that triggers an element to be filled with a different view. I am aware of the .load function in JQuery ( http://api.jquery.com/load/ ), but that does not explain how to include such functionality in a CakePhp environment. Can I simply use something like 'controllername/add' as url parameter for load?
As I see it, one issue remains despite the element solution (which might result from my limited Cake knowledge) - concrete example: The application has tables for companies, users and posts, each table and corresponding controller has index / add / view(show the data) / edit views. Index is displayed in the main area, the other views are supposed to be displayed in the slideout. Would I not need many different element specifications depending a) on the chosen table b) the chosen option (add / edit / etc) ?
Is there a way to put for example the rendered view of "View/Company/add.ctp" into an element? Because as far as I understand requestAction, I can only get the data provided by the controller (which makes sense due to the MVC pattern) and this data still has to be echoed and styled. And that is the problem since there is not a common style for add / edit / view (add and edit would have inputs for data values, view would use labels). My thought would be to put those options into one element and control which style is used by a parameter given to the element, I just want to know if that is viable or if there is another, better way to do this.
I hope that was somewhat intelligible :) Many thanks in advance for any helpful advice
> Thanks a lot for your answer, it helped me a lot!
> I see how elements can be used for what I am trying to do. I tried the > simple example from the link you provided, so now I can populate > multiple ares of one page with different views - that's great!
> What I don't quite grasp is the usefulness of adding a helper as you > mentioned in your last paragraph. So basically the helper would get > all the data for my elements instead of me calling requestAction > multiple times?
> I was told that AJAX can be used to put content into element areas > (via requestAction, too?), e.g. I have my slideout visible which shows > a data entry, then, with my table still visible in the main content > area, I choose edit on a different entry and instead of loading the > page anew, the slideout element loads new content. How would one go > about this task? A simple example would be enough to get me started, > since I cannot find any useful ones, e.g. a button that triggers an > element to be filled with a different view. I am aware of the .load > function in JQuery ( http://api.jquery.com/load/ ), but that does not > explain how to include such functionality in a CakePhp environment. > Can I simply use something like 'controllername/add' as url parameter > for load?
I use it in this way: $("#someelement").load("/controller/action div.index"); loads html content of div.index in #someelement
You can handle it better with $.post / $.get handling the html response $.get('controller/action', function(html){ var myHtml = $(html); $("#something").replace( myHtml.find("#something").html() );
});
This works faster if you create an empty layout and print only the $content_for_layout, I use it with a custom extension eg. controlller/index.dhtml give me only the action response, without the whole layout code around.
> As I see it, one issue remains despite the element solution (which > might result from my limited Cake knowledge) - > ... > Is there a way to put for example the rendered view of > "View/Company/add.ctp" into an element? > ...
I don't know a lot about AJAX - Need to learn :-) What I am doing with the helper, is that I was finding that I was repeating code in multiple views or several times in a single view to get ready to call an element. So, I just moved this common code from the view to a helper, then made a single to call to the helper.
In Controller public $helpers = array ('Html', 'Form', 'Session', 'Address');
In Helper public function makeAddressElements($organization) { // some details removed.... $addresses = $this->requestAction('addresses/getByOrg/'.$organization['id']); foreach ($addresses as $address) { $title = "Not Used Address"; if ($organization['ship_address_id'] == $address['Address']['id']) $title = "Shipping Address"; if ($organization['bill_address_id'] == $address['Address']['id']) $title = "Billing Address"; $html .= $this->_View->element('address', array("addr" => $address['Address'], "title" => $title)); } return $html; }
In the Helper in order to call an element that is associated with a view, you need to use the call $this->_View->element(). This will used the attached view to help render the element. This is not well documented, but seems to be the way other helpers do this.
You may not need to do this since you are doing Ajax. You may be able to load all this stuff in the beginning and have javascript hide and display the details as needed.
As for the controller function mapping to views, while Cakephp will defualt create add / index / edit / view functions and views, you are not required to use them all. If you want to have everything displayed and managed for the controller thru the view function and the view view, I don't think this is a problem. You could then use requestAction, or a bunch of set commands to pass information to the view.
This is where my Ajax knowledge puts me on thin ice, but I think you can create Ajax or javascript functions that can call other functions in the controller, like add or edit, and return information that you updated a portion of the screen, so that you don't have to render the entire page.
I guess the way I would look at this is that the view is the webpage. If you want everything to be processed in a single page, with pop outs, etc. then you only need one view. It may be complicated, but if you are familiar doing this with just PHP and Ajax then it should be fine. The controller is where all the business logic is run. So this can be organized based on how you want to process the data.
Not sure if I am getting to basic here, or if this answers your question about views.
> Thanks a lot for your answer, it helped me a lot!
> I see how elements can be used for what I am trying to do. I tried the > simple example from the link you provided, so now I can populate > multiple ares of one page with different views - that's great!
> What I don't quite grasp is the usefulness of adding a helper as you > mentioned in your last paragraph. So basically the helper would get > all the data for my elements instead of me calling requestAction > multiple times?
> I was told that AJAX can be used to put content into element areas > (via requestAction, too?), e.g. I have my slideout visible which shows > a data entry, then, with my table still visible in the main content > area, I choose edit on a different entry and instead of loading the > page anew, the slideout element loads new content. How would one go > about this task? A simple example would be enough to get me started, > since I cannot find any useful ones, e.g. a button that triggers an > element to be filled with a different view. I am aware of the .load > function in JQuery ( http://api.jquery.com/load/ ), but that does not > explain how to include such functionality in a CakePhp environment. > Can I simply use something like 'controllername/add' as url parameter > for load?
> As I see it, one issue remains despite the element solution (which > might result from my limited Cake knowledge) - concrete example: The > application has tables for companies, users and posts, each table and > corresponding controller has index / add / view(show the data) / edit > views. Index is displayed in the main area, the other views are > supposed to be displayed in the slideout. > Would I not need many different element specifications depending > a) on the chosen table > b) the chosen option (add / edit / etc) ?
> Is there a way to put for example the rendered view of > "View/Company/add.ctp" into an element? Because as far as I understand > requestAction, I can only get the data provided by the controller > (which makes sense due to the MVC pattern) and this data still has to > be echoed and styled. And that is the problem since there is not a > common style for add / edit / view (add and edit would have inputs for > data values, view would use labels). My thought would be to put those > options into one element and control which style is used by a > parameter given to the element, I just want to know if that is viable > or if there is another, better way to do this.
> I hope that was somewhat intelligible :) > Many thanks in advance for any helpful advice
> Timo > -- > Our newest site for the community: CakePHP Video Tutorials > http://tv.cakephp.org > Check out the new CakePHP Questions site http://ask.cakephp.org and > help others with their CakePHP related questions.
> To unsubscribe from this group, send email to > [hidden email] </user/SendEmail.jtp?type=node&node=5648786&i=0> For > more options, visit this group at http://groups.google.com/group/cake-php
thank you both for your advice, it helped me to get going and so far I was able to implement the design I had in mind using elements and ajax. Should I encounter more difficulties, I will post them here.
Oh and bs28723: No worries that you might've been too basic, I'm always glad for any advice, especially since I'm just beginning to learn Cake :)