Need a simple CRUD for single page application.
Permalink 1 user found helpful
I am new in concrete5. I want to create a simple CRUD for single page. Let me describe all steps that i have done on my system.
I have create a page that is "add.php" (application/dashboard/folder/add.php)
I have create a page that is "view.php" (application/dashboard/folder/view.php)
After that i have created a form on add.php file.
Now i have registered both page from "Pages & Themes >> Single Pages". Its successfully added.
After that i have created controller for fetching data from database. that is add.php on path (applications/controllers/dashboard/folder/add.php). I have write below code on app.php file but its not working.
My controller Code :
My view code :
When i do any small changes in controller file i will refresh link from add single page section. After that remove cache and then Ctrl+f5
I have create a page that is "add.php" (application/dashboard/folder/add.php)
I have create a page that is "view.php" (application/dashboard/folder/view.php)
After that i have created a form on add.php file.
Now i have registered both page from "Pages & Themes >> Single Pages". Its successfully added.
After that i have created controller for fetching data from database. that is add.php on path (applications/controllers/dashboard/folder/add.php). I have write below code on app.php file but its not working.
My controller Code :
<?php namespace Application\Controller\Dashboard\Folder; use Concrete\Core\Page\Controller\PageController; class DashboardFolderController extends Controller { public function view() { echo 'this is View'; // faqList this variable will access on view page $this->set('faqList', 'dddddddddddddddddd'); } }
My view code :
When i do any small changes in controller file i will refresh link from add single page section. After that remove cache and then Ctrl+f5
Thanks you very much for your support.
Thanks
Thanks
I do exactly like you mentioned above.
Now when i submit my page i got "page not found " error. On submit i got this URL :http://localhost/concrete/index.php/dashboard/folder/add/submit...
Please check my controller code :
This controller file situated on : /var/www/html/concrete/application/controllers/single_page/dashboard/folder/add.php
My Form code :
This form file situated on :
/var/www/html/concrete/application/single_pages/dashboard/folder/add.php
I got this error after submitting.
Page Not Found
No page could be found at this address. Back to Home.
Now when i submit my page i got "page not found " error. On submit i got this URL :http://localhost/concrete/index.php/dashboard/folder/add/submit...
Please check my controller code :
<?php namespace Application\Controller\Dashboard\AddFonts; use Concrete\Core\Page\Controller\PageController; class DashboardAddFontsController extends Controller { public function view() { echo 'this is View'; // faqList this variable will access on view page $this->set('faqList', 'dddddddddddddddddd'); } public function action_save_attribute() { echo ';eeeeeee'; die("PPPPPPPPPPPPPPPPPPPPPPPPPPPPP"); } public function action_save_google_api(){
Viewing 15 lines of 27 lines. View entire code block.
This controller file situated on : /var/www/html/concrete/application/controllers/single_page/dashboard/folder/add.php
My Form code :
<div class="form-group"> <form action="<?php echo $this->action('save_google_api')?>" method="POST"> <table width="100%"> <tbody> <tr> <td><label for="apikey" class="control-label"><?php echo t('Enter API KEY'); ?></label></td> <td><input type="text" id="apikey" name="apikey" value="" autofocus="autofocus" autocomplete="off" class="form-control ccm-input-text"></td> <td><input type="submit" id="apikeyBtn" name="apikeyBtn" value="Save API" class="btn btn-primary pull-right"></td> </tr> </tbody> </table> </form> </div>
This form file situated on :
/var/www/html/concrete/application/single_pages/dashboard/folder/add.php
I got this error after submitting.
Page Not Found
No page could be found at this address. Back to Home.
Controller Correct Code :
<?php namespace Application\Controller\Dashboard\Folder; use Concrete\Core\Page\Controller\PageController; class DashboardFolderController extends Controller { public function view() { echo 'this is View'; // faqList this variable will access on view page $this->set('faqList', 'dddddddddddddddddd'); } public function action_save_attribute() { echo ';eeeeeee'; die("PPPPPPPPPPPPPPPPPPPPPPPPPPPPP"); } public function action_save_google_api(){
Viewing 15 lines of 27 lines. View entire code block.
after you created the proper files you needed to delete the single page you created in C5 and create them again.
Also, your namespacing seems incorrect since it doesn't include SinglePage. The namespacing should reflect the folder structure.
I strongly suggest you look at concrete5 core code to see how they do it. They only difference is they'll have Concrete and you'll have Application
Also, your namespacing seems incorrect since it doesn't include SinglePage. The namespacing should reflect the folder structure.
I strongly suggest you look at concrete5 core code to see how they do it. They only difference is they'll have Concrete and you'll have Application
Hello Sir,
Please check attachment and let me know. I have created files and code exact like you mentioned but still unable to call any method of controller.
If possible so kindly fixed this and give me correct zip.
Thanks in advance.
Please check attachment and let me know. I have created files and code exact like you mentioned but still unable to call any method of controller.
If possible so kindly fixed this and give me correct zip.
Thanks in advance.
Done this issue. Thanks for your help.
I need to add a style and script globally. I have used below code but it is working only for my controller. When i move to other page my style and script will not add there.
I need to add a style and script globally. I have used below code but it is working only for my controller. When i move to other page my style and script will not add there.
$this->addHeaderItem('<style type="text/css"> .mytyle { display:none;}</style>'); $this->addHeaderItem('<script> alert("Here")</script>');
If you call assets from a single page controller it will only load for that page.
If you want to load them sitewide there are other ways.
You probably can do it from the file application/bootstrap/app.php which is designed to do things like that and more (read the comments inside the file)
I haven't tested it but I think the following code would work (in application/bootstrap/app.php)
If you want to load them sitewide there are other ways.
You probably can do it from the file application/bootstrap/app.php which is designed to do things like that and more (read the comments inside the file)
I haven't tested it but I think the following code would work (in application/bootstrap/app.php)
use View; $v = View::getInstance(); if (is_object($v)) { $v->addHeaderItem('Here put the code you wan to add to your pages'); }
Thanks you are awesome and your support is too awesome. Very thanks again.
Pritesh Mahajan
Pritesh Mahajan
If you are creating single pages, the views should be in application/single_pages/dashboard/folder/view.php and application/single_pages/dashboard/folder/add.php
And the controllers should be in application/controllers/single_page/dashboard/folder/controller.php and application/controllers/single_page/dashboard/folder/add.php
Several important things to note here:
for the views, single_pages takes an "s" but for the controllers, it is single_page with no "s" it was not a typo
The second thing to note is your first view is the file view.php. When using the file name view.php, its controller has to be named controller.php and in that case, the page's name is the folder containing those files so in your case the page URL will be yoursite.com/dashboard/folder
On the other hand, if you name your view something else like you did with add.php, then the controller has to be named the same thing. In that case, the page is named like the files so your page URL will be yoursite.com/dashboard/folder/add