Dynamically Add Multiple Cgridview on a single Page - php

I'm trying to figure out how to let the user add any numbers of tables or CGridview on a single page. So right now the page has two gridviews in it which will stay fixed. Now i want to add an add button somwhere, clicking on which will give the user another gridview, and so on.
How should i proceed with this. I mean is there an easy way to do this, without resorting to writing everything from scratch.
What i was thinking was to create a new view file using file_put_contents() or fwrite() dynamically everytime the user wants another table on the page? Now following in my line of thinking from where would i create these dynamically view files.
Should i write the whole code of the view and put it in a string, in the controller, and call file_put_contents() from there.
This would cause another problem as the filter needs a specific ajaxUpdate url like this
'ajaxUrl' => Yii::app()->createUrl('project/AjaxUpdate'),
.
Which would entail i would have also have to dynamically create the actionCode in the project controller for the filter in that dynamic grid to work. eg. project/AjaxUpdateDynamic1, project/AjaxUpdateDynamic2, etc.
So i'm kinda stuck with this problem. I would really appreciate if someone points me in the right direction.
Thanks, in advance,
Maxx

if you had an action for ajax loading your gridviews, you can then set your ajax url to that url and you'd have filtering possible for your model, you can even put multiple gridviews for multiple data providers that can be loaded via a parameter that you have sent along with click of your button and an input.

Related

let user disable certain array items?

This is the situation, I've got a big array ( 280 items ) which creates a really big form by going trough loops.
I want the user to be able to disable certain items, so they can 'pre make' their form ( and skip the not used ones ), You are probably going to say i can just remove what's not needed. But they need different items from the array every time they use it.
So how would i make a page where they can just use checkbox to 'change' the form. ( if possible at all.)
Thanks,
Mike
edit:
Did not think of sharing code, here:
The array : http://pastebin.com/EnwHsqtK
the form : http://pastebin.com/y2XSFBG4
the page which makes a .txt file from the given answers. http://pastebin.com/UaUcsj2z ( not sure if anyone would need this. )
Might be a bit messy. I'm new in PHP, and only programming for a year. Also dont mind the language please.
If you want to permanently record form preferences/settings for each user, you'd want to create an additional table or column(s) in your database for this, give the users additional checkboxes on the form to indicate their preferences, receive this input and store it in the database, and of course finally disable certain fields based on their settings.
But if you just want to give the users a temporary way to disable certain fields (with no preferences saved permanently), you would use JavaScript in your output. You would add more form controls (checkboxes or buttons or whatever) to the HTML and then add JavaScript code snippets into that HTML to disable form elements when the user clicked on the controls. This kind of making changes when users click is called "triggers that fire based on events". The most commonly-used event is called "OnClick()" and the JavaScript code for it will execute when a user clicks on something.
Many folks who use JavaScript also find it helpful to use the functions in the jQuery library instead of raw JavaScript. To do this, you just add one line of HTML to the top of your page to include the JavaScript libraries from a publicly-hosted server, then you can use jQuery commands in your page.
The only thing to remember when you first start using JavaScript/jQuery is that it only runs on the client browser - its code cannot talk directly to the server, the database, or many things you can access in PHP. JavaScript/jQuery is specifically used for making your HTML pages more interactive. Plain HTML doesn't have much razzle-dazzle. JavaScript allows users to do things like enable and disable form fields on-the-fly.

Functions and parameters - is there a better method?

I'm looking at neatening my file structures and code. At the moment I'm making an image gallery, it has a management page which allows the user to upload, edit and delete images/information.
To upload an image, the user would select their files, sumbit the form and arrive at uploaded.php.
To delete an image, the user would click a link taking them to delete.php?id=IMAGEID.
To edit an image, the user would be taken to a page with an editor. Upon making any revisions they'd then be taken to edit.php?id=IMAGEID.
Each page runs either a function. I feel it's unecessary to have three different pages to run three different functions. Is there any way I could neaten this process?
Well, it just depends on how you like to manage your files and how you are using your IDE when you've to edit something.
If you're working alone, it's clearly up to you. If you know someone will, maybe, have to rework your code someday, having three files could be a plus, somehow.
I guess you're not concerned about SEO for these pages, but just in case the problem appears again, it could be better to have actions in parameters, rather than in files name.
/manage.php?edit or /manage.php?delete or /manage.php?upload
But, if your code is really really big, using three files could still result in a lower use of memory (Well, very slight improvement, but still)
Exactly you don't need 3 pages for each function
1)Delete ,instead of redirection the user to a different page and delete it ,you can add an image button which delete icon and when user click on it ,it call a specific function in your php and delete it then refresh your page.
2)Edit and Insert : these are 1 page ,like make your insert page if it doesnt have a query string with the Image ID then it's insert function ,else it contains and ID then load the content of this Image inside your inputs and while saving check if there is ID then update else insert new record
So,you moved from 3 pages to 1 page only.Hope this helped you.

using "child" pages or iframes or other within php

trying to figure out how to best display a bunch of information on a "mother" page.
When I enter the first page, which is populated based on a GET method for a specific "id". on this page, I want to have an area where the user can click on either a link or button or other which will display a subsection in a single location. These pages will need to display the appropriate information based on data located on the page.
Would the best way just to be to create an iframe?
I'm unclear, as to how I best get this information to change appropriately (i'm still quite new to this process).
would I continue to use the GET method still on the "child" page; Do I also need to use a POST method somewhere?
any guidance would be great.
The better approach is to use ajax to populate that div.

CakePHP - generating different pages/views dynamically using a menu

I'm a total beginner to CakePHP, and I'm trying to build a pretty basic website here that has a menu + some UI stuff like a footer that will persist through all the pages.
The trouble that I'm having right now is that in my controller, I have several different functions corresponding to the website's menu options that grabs data from database, but obviously I wouldn't want to create the same number of views since every page has the exact same setup.
So my question is what's the standard or best practice to achieve this? I read up on elements and am still kinda confused as to how this would be done; how would I keep track of which page is the user currently browsing? And if they click on a menu option, how would it be coded so it takes them from "blah.com/home" to "blah.com/contact"?
I know my question is kinda long and noobish but I'd really appreciate it if I could get some help in beginning CakePHP.
For functions corresponding to the website's menu options that grabs data from database, put these in beforefilter() of the App Controller and use $this->set to set variables and make element for menu which you can call in your layout. You can set the layout in your controllers like var $layout=''.

multiple action for one submit button cakephp

is it possible to have a button that calls two different actions in two different controllers in a cakephp application? For example, let's say that I have a text box on a page and a next button, when I click the next button I want the data entered into the text box to be saved to the database and move to the next page (the moving to another page is another controller action)
Is this possible?
Let me know, thank you
Your concept is totally wrong thought. There are different approaches but your "two buttons" is totally miss-leading. I guess because you did not understand the MVC design pattern, read about it.
When you submit your form from, lets call it /reports/step1 and the data validates simply save it and redirect to /reports/step2.
Different forms that do different things should be always separated. If you start to do multiple things in the same action and view things become messy for sure. Simply go for best practice techniques: If a method is doing two things at once refactor it.

Categories