Load another view when click on a image - php

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

Related

Load a view by clicking in a button CodeIgniter

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);

On redirecting to a View, slide it to the specific part of the page using #id - Laravel 5.3

I have a route which redirects to a controller which tells view to show. But how can I go to a particular part of the page. Let me Explain:
I am using fullpage.js library to create a page breakpoints.
for example: /home#firstPage , /home#secondPage and so on. When I am redirected to /home I would like to go to a particular section of the page. All I need is a way to enter #3rdPage in url.
Where and How do I put this to see it action?
my Routes
Route::get('/home_done', ['as' => 'home_done','uses' => 'HomeController#home']);
my Controller
public function home()
{
return view('home_done');
}
I would like to do something like:
return view('home_done#3rdPage');
You should setup a new function and route to redirect the users to correct page after executing your logic:
public function home()
{
return view('home_done');
}
public function step_3()
{
// do something and redirect
return redirect('home_done#3rdPage');
}
Using view don't work since you are loading a file, not the page.
You need change your behavior in JS, when a user comes to your page without a # consider it equal of #firstpage.
and in your html manage all over pages by properly generate urls with #what_you_need.
in your blade example:
firstpage
//OR
firstpage //because this is the same for your JS
secondpage
or blade syntax
firstpage
//OR
firstpage //because this is the same for your JS
secondpage

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.

creating codeigniter dynamic template

i want to put login form in navigation(template) so that it will be shown in all the pages.
and will check username and password in database without going to other pages. if failed, an error will be shown in the nav and if success, the page will be reloaded again with specific costomizations. please tell me how with code and details.
i have these parts in my template:
header
nav
footer
and content that will be added in current controller
i wanna do this in each controller:
$this->load->view('templates/header');
$this->load->view('templates/nav');
$this->load->view('related_view');
$this->load->view('templates/footer');
but my navigation should contain a login form which will not go to another page by submitting.
I usually do something like this:
<?php
$this->load->view('templates/header');
if ($this->user_model->isLoggedIn())
{
// Logged-in users should see this view
$this->load->view('templates/nav-registered');
}
else
{
// Guests should see this
$this->load->view('templates/nav-guest');
}
$this->load->view('related_view');
$this->load->view('templates/footer');
You'll thank yourself if you override the Loader class to grab your header/footer for you automatically, not having to code this in EVERY controller method. Just a thought..
use session to check loged user, and put this on the nav view, but first make sure you have session loaded from auload or from your controller
if($this->session->userdata('user_loged')){
//code to put some navigation when use is loged
}else{
//code to put login form
}
The solution I found is to extend the Controller class. So In this case we should make an extended controller (for example MY_Controller) and put the dynamic action (here authentication) in it as a method.
Then we should extend this self-made controller in each of our controllers , so authentication in the template would be simply handled.

codeigniter won't add a simple view

I'm trying to add a view just a simple contact page, I already have other views.
Here's what I've done so far:
added 'contact' in my routes file here
$route['^(?!/|site|ajax|gallery|contact).*'] = "site/view/$1";
added contact.php to my application/views folder
added contact() to my site controller (whole controller here http://pastebin.com/CCjjrV8R)
function contact() {
$this->load->model('Site_model');
$this->load->view('contact');
}
When I visit the correct url for the view (domain.com/contact), I get a page with partial content and "404" in the
Can anyone see a problem? This is very puzzling.
I don’t think you need the view part of the URL in the route?

Categories