Load a view by clicking in a button CodeIgniter - php

I'm trying to load a view by clicking <a> with CodeIgniter.
below is my code:
<a class='b2' href='<?echo base_url('application/views/create_account')?>'>CREATE AN ACCOUNT</a>
but when I click it, I receive the message :
Forbidden
You don't have permission to access this resource.
Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.
the view name is correct.
How can I load a view by clicking in a link or a button?

CodeIgniter is MVC based library. It can not load view directly without using controller.
Try this :-
1> Create A Controller in application/controllers.
class Createaccount extends CI_Controller {
function index() {
$this->load->view('create_account','');
}
}
2> Create route in application/config/routes.php.
$route['create_account'] = "CreateAccount";
3> Use below code in html :-
href = "< ?php echo base_url().'create_account' ?>".

pass to the controller first
In view page:
CREATE AN ACCOUNT
In controller:
public function function_name(){
$this->load->view('create_account', $data, FALSE);
}

Just pass second parameter to load view method as true
$this->load->view('create_account', true). This true will pass the html data from controller and than you can show that data to your existing page via jQuery or other.
In your controller you have to return view like,
echo $this->load->view('create_account', [], true);

Related

url redirect in mvc . i want to redirect localhost/windshield-replacement.html to localhost/greenvalleyaz

My applications is now in phalcon php framework. I want to redirect a url which contain .html at the end. To redirect, I wrote the controller name as WindshieldReplacementHtmlController.php but because of the dot in between I could not redirect. How can I solve this?
Redirect from:
localhost/windshield-replacement.html
to
localhost/greenvalleyaz
When I type localhost/windshield-replacement-html its redirecting to the target but when i use localhost/windshield-replacement.html its not detecting the controller.
is it the correct way to do that ?
In MVC you should not show the View Directly
you have to access a controller action --> in action you have to render view
In the Example I want to show user/order.phtml
I will access this page from Browser localhost/appname/user/orders
UserController.php
use Phalcon\Mvc\View;
class UserController {
function ProfileAction(){ //access localhost/appname/controller/profile
}
function loginAction(){ //access localhost/appname/controller/profile
}
function ordersAction(){ //access localhost/appname/controller/orders
$view = new View();
// Setting views directory
$view->setViewsDir('app/views/');
$view->start();
// Shows recent posts view (app/views/user/orders.phtml)
$view->render('user', 'orders');
$view->finish();
// Printing views output
echo $view->getContent();
}
}
Refer : Phalcon_Mvc_View

Link to a another page from a dynamic page in laravel

I created a dynamic page by taking data from the database.
Example: example.com/post/SE12
This /SE12 is dynamically created. Now I have a button in this page where I want to edit the post.
example.com/post/SE12/edit.
How can I link a button to this page using laravel? and how can I route this page and call it in controller?
In route.php
Route::resource('posts','PostsController');
Route::get('/posts/{code}', [ 'as'=>'post-show', 'uses'=>'PostsController#show']);
routes.php:
Route::get('post/{code}/edit', [ 'as'=>'post-edit', 'uses'=>'PostsController#edit']);
Controller:
public function edit($id)
{
echo $id; //this will give the code. e.g. SE12
}
View:
some title
N.B. you are resource controller and manual mapping at the same time. stick to either one as much as possible. otherwise routes will get conflict.

CakePHP Controller Action not Rendering

I have a CakePHP Action that is not rendering it's view, however the action is being executed.
I have the controller VoteTagsController with the action alltags()
App::uses('AppController', 'Controller');
class VoteTagsController extends AppController {
public function index(){
$this->set('allVoteTags', $this->VoteTag->find('all'));
}
public function alltags(){
echo "Running";
echo "Test";
}
}
The view exsists also in /View/VoteTags/alltags.ctp
I am attempting to load the action from http://test_site.dev/votetags/alltags
I've tried everything but cannot get this view to render I just get a white page, no errors.
Changing the name of the controller however and refreshing sends me to an Error Not Found page which indicates the action is being fired but not rendered.
Any ideas?
Based on conventions your URL should be test_site.dev/vote_tags/alltags
If you wish to change this you can add to your app/Config/routes.php file the following line
Router::connect('/votetags/alltags', array('controller' => 'vote_tags'))
Or whatever other url template you might like.
For more information read http://book.cakephp.org/2.0/en/development/routing.html

calling a different action in the same controller

I'm developing a small app. using php and Zend Framework. I have a form, and I use it's controller to view the form. Now I need to manipulate the form data and redirect the user accordingly.
here is my controller
<?php
class NewuserController extends Zend_Controller_Action {
public function init()
{
/* Initialize action controller here */
}
public function newuserAction()
{
$this->view->newuser;
}
public function adduserAction(){
$data = $this->getRequest()->getParams();
$u = new User();
$u->setUserName($data['uName']);
$u->setPrepwd($data['pwd']);
$u->setPrepwd($data['pwd']);
if($u->isEqual()){
$val = $u->addUsers();
if($val)
$this->_helper->redirector('main','main');
}
else
$this->_helper->redirector('newuser','newuser');
}
}
?>
my view is newuser.phtml. In the action attributr of the <form> I have specified Newuser/adduser . But when I submit the form it again displays the newuser.phtml.
Why is this?
Thanks in advance
Charu
You can forward the request instead of redirecting:
$this->_forward('newuser');
I would suggest that you use the redirector helper instead of the foward because if you want the user to be redirected to the main page with foward it will redirect but it won't change the url so if they were to bookmark the page for example it wont work. If you use the redirector it will redirect and change the url to show just your main phtml page. Also if you are in the same controller its not necessary to include the second param which is the controller. Check this out for more help
http://framework.zend.com/manual/en/zend.controller.actionhelpers.html#zend.controller.actionhelpers.redirector

Load another view when click on a image

I am using codeigniter for a project. I set controller A as my default controller in routes.php. So in this controller A it will load my home page.
If I want to access another view from the homepage for example about or contact, how do I go about doing it??
Example:
<a href="http://yoursite.com/yourcontroller/yourfunction">About Page
Now you have yourcontroller that has the yourfunction in it, from within this function you can load the view for about page, like:
function yourfunction() {
$this->load->view('your_about_view_page_name");
}
And that shall work. Hope it helps

Categories