CodeIgniter link routing - php

Hi i am new in CodeIgniter. How to give a link to next page like HTML in codeigniter.In HTML we use page name. How to do this thing in codeigniter?

Try using
Some Name
Some Name
I would use base_url() for view files when linking or anchor();
anchor('controller_name', 'Some Name');
anchor('subfolder/controller_name', 'Some Name');
Auto-load the URL helper
You may need to set custom routes for controller Routing In Codeigniter
CI2 & CI3 User Doc's Here. Codeigniter Docs

Goto application >> config >> autoload.php
change line
$autoload['helper'] = array("url");
and change link to
MyLink
'controllername' should be your desired controller name and 'functionname' the same as desired!

You can try so-
Link
CodeIgniter - Correct way to link to another page in a view
codeigniter linking to another page

Related

How can I move the login behaviour from the /login URL to my home page in a Laravel application?

I am pretty new in PHP and moreover in Laravel framework (I came from Java) and I have the following problem related to Laravel security.
I have correctly configured my Laravel login system so if I access to the page:
http://localhost:8000/login
I obtain my login page from where I can access to the restriced area of my portal. This is the standard Laravel login page.
My doubt is: can I take this behavior into my home page? Because I have to put the login into a custom login from into my home page (the one that is automatically opened launching http://localhost:8000/).
How can I do this?
From your question i understand that:
You are adding the login form in the homepage and not trying to provide the link to the login page from homepage.
If this is not your question i could delete my answer.
So, if you are using blade you could easily import the chunks of codes from login page.
More on Sub-view Here:
https://laravel.com/docs/5.3/blade#including-sub-views
Example:
login.blade.php
<div class="form">
//your login form contents
</div>
homepage.blade.php
//your homepage codes
#include('login')
//rest of your homepage codes
Note:
The path to your subview is relative to resources/views/.
i.e. If you have this folder structure like this:
|-resources
|-views
|-homepage.blade.php
|-partials
|-login.blade.php
then you will need to use:
#include('partials.login')
in your homepage.blade.php to use that view.
Inside web.php add this route at the end of the routes
Route::get('/', 'Auth\AuthController#getLogin');
You can update routes file in laravel like below.
Basically your routes file is located in
YourProject/app/Http/routes.php
here you can copy the View(blade) / Controller of /login route to /. Like example shown below.
Route::get('/login',function() {
return view('login');
});
Replace the above one to
Route::get('/',function() {
return view('login');
});
example above is without controller.
Hope it works!!

How to call one controller(function) view with multiple url in codeigniter via routes.

I create a controller function home/index .
calling vai url it is showing me html design.
I want to call the view of home/index via custom urls.
If I type
www.example.com/home_new // it will open view of home/index
www.example.com/home_new1 // it will open view of home/index
Also i want to save the custum urls in database so that admin can change.
Please advise how to do this via routes or another method.
Add this code to inside route.php file:
$route['home_new'] = 'home/index';
$route['home_new1'] = 'home/index';
This will solve your problem. For database it will not help you.
You can take reference from this link.

how to load my default controller in codeigniter using bootstrap?

i have a view with bootstrap template which is embedded at my view/reportlist.php (localhost/Project/index.php). the problem is that every time i perform a CRUD, well codeigniter reroutes me to deffirent uri. example, when i edit a report from my list, i will be redirected to my view/reportlist.php (/Project/index.php/report/edit). then my bootstrap template is ruined. i need to go back to the /Project/index.php to load back everything up. please if you know, post some ideas, ive been like this for days now, i cant find a relevant answer.
there is no relation between codeigniter route and bootstrap. you can set you default controller in line 41 in: application > config > route.php file.
on ther other hand you can set you base_url in line 17 in: application > config > config.php by this:
$config['base_url'] = "http://".$_SERVER['HTTP_HOST'];
$config['base_url'] .= preg_replace('#/+$#','',dirname($_SERVER['SCRIPT_NAME'])).'/';
I'm sure that you have call again the list view in you edit method in report controller :D .
if you want to avoid index.php from you url then you can modify code in your .htdocs files:
In your form action attribute specify a route: <?php echo base_url('/someRoute'); ?>, and in routes.php map it to some specific controller: $route['someRoute'] = 'home/someRoute';, from this controller load your desired view.

URI routing in codeigniter

As the title suggests, my issue is with codeIgniter.
I have used a code in an .htaccess file to remove index.php which works all OK.
But I need to go further in changing the URI:
My main controller is page(), so when a user is in my homepage, the URL-bar shows:
www.example.com/page/
(because homepage is index page, it does not show the page name as usual the controller suffice),
but If I go to registration page, the URL-bar shows:
www.example.com/page/register
Up to here everything is OK, but I want the codeIgniter to show my domain without the page() when the user is in my homepage, I don't want foolish www.example.com/page/ to appear and I think when someone is visiting index page, the URL-bar better to be www.example.com
You can define a custom route in config/routes.php - for example:
$route['default_controller'] = 'page';
Then, http://example.com
goes to http://example.com/page
then if you did not specify any data , it will route to default controller.
for the link to register:
www.example.com/register
in config/routes.php
$route['register'] = 'page/register';
You have everything explained here in great detail.
http://ellislab.com/codeigniter/user-guide/tutorial/static_pages.html there is an example here on the bottom how to do uri routing with routes.php file in codeigniter.

CodeIgniter - creating forms with .html link

I want to create a simple website with 5 pages which contains 2 simple contact us forms.
The links should be www.yoursite.com/contact.html and after submitting it should go to www.yoursite.com/success.html. Please help, I have searched a lot for it but couldn't find anything
[edit]
I have a different controllers for different forms but in the links i don't want the controller name but only the view name.html
If all you want to do is change the apperance of the URLs, then you could use CodeIgniter's routing. You'll most likely also want to remove index.php from the URL, more information is available in CodeIgniter's user guide.
For example, if you have a controller named Contact with an index() function that loads the view for the contact form, and another function success() that loads the success page view:
Then this route, in application/config/routes.php would map the URL, www.yoursite.com/contact.html to your Contact controller.
$route['contact.html'] = "contact";
This route would map www.yoursite.com/success.html to the success() function within the Contact controller.
$route['success.html'] = "contact/success";
If you want your Codeigniter URLs to have ".html" appended to them for some reason, you should modify your application\config\config.php file and change
$config['url_suffix'] = '';
to
$config['url_suffix'] = '.html';
You can see here for more info.

Categories