codeigniter path issue - codeigniter

I am trying to link my view page to another controller.
my test_view.php page
//this page address is base_url/controller1/function1
<a href='controller1/function2'> test </a>
If i click, the page address will be base_url/controller1/function1/controller1/function2 which is not my desire.
my controller
//the first function1 is to show my test_view page
function function1 (){
$this->load->view('test_view');
}
//I can't get to this function2 with the link I used
function function2 (){
$this->load->view('funny');
}
Anyone could help me about this? Thanks a lot.

Sure--you just need to tell CodeIgniter to display the path:
<a href="<?php echo site_url("controller1/function2");?>">
One thing: This displays the absolute path of your site as defined in your config, not the relative path.
I prefer relative paths, so I like to create a universal function called site_path to do the same thing without the absolute URL. I include it in one of my universally loaded libraries and it looks something like this:
function site_path($url) {
return "/$url";
}
The benefit of this is that, if I initially develop the site in a subdirectory, I can set site_path to return "/subdirectory/$url" and then just remove the subdirectory once I launch.

It's linking to a relative URL, you need to start with a '/' to use the web root
<a href='/controller1/function2'> test </a>

you can use following code in test_view.php page,
<a href='<?php echo base_url();?>controller1/function2'> test </a>

Related

How to correctly redirect with inertia in laravel?

I'm trying to redirect to another page with the click of a button, but for some reason it's not working, I'm not sure why?
Currently it opens up a window inside the main page not even a real redirect but it's blank. If I change the link to something else like just "/" or another page like "/users" then it works, but just for this link it's not working.
This is how I'm redirecting in the vue
<inertia-link href="imports/teachers">
<el-button type="warning">Import</el-button>
</inertia-link>
In my web.php
Route::resource('imports/teachers', 'ImportTeacherController');
In the controller
public function index()
{
return Inertia::render('Import/Teacher');
}
In the teacher.vue I have a very basic layout
<template>
<layout>
<div>
<h1>Page Title</h1>
</div>
</layout>
</template>
<inertia-link href="imports/teachers"> -> <inertia-link href="/imports/teachers">
You are missing a / before imports. It's just the same with normal anchor tags, you should add a leading /.
You must make <inertia-link href="/imports/teachers">
There is also an even better solution which I always use. With this you can use routing names just have a look at it then it goes like this <inertia-link href="route('import.teachers')"> https://github.com/tighten/ziggy
Or you add it manually how it works you can find here: https://inertiajs.com/routing at Generating URLs.

Laravel 5 requested url shows blank page with no error

I want to show a page when a url is requested but what i get is a blank page despite the fact that the page has content in it. I've been trying to figure what could be wrong with my code but have come up with nothing so far. Here's what i have in my code
In my web.php file, i have this route
Route::get('/home', 'HomeController#index')->name('home');
// Student
Route::get('/students', 'StudController#index');
Route::get('/student/create', 'StudController#create');
Route::post('/students', 'StudController#store');
// Employee
Route::get('/employees', 'EmpController#index');
Route::get('/employee/create', 'EmpController#create');
Route::post('/employees', 'EmpController#store' );
Route::get('/employee/{id}', 'EmpController#show');
// Faculty
Route::get('/faculty', 'FacultyController#index');
In the EmpController file, this is the method to show the employee with the id (note the absence of a query as I'm only testing to see if a page is displayed when this uri is requested)
public function show()
{
return view('emp.employee');
}
This is the link
<i class="fa fa-file-text-o" aria-hidden="true"></i>
This is my employee.blade.php inside the resources/views/emp/ folder
#extends('layouts.master')
#section('content')
<h3>Why is this page blank?</h3>
#endsection
Error reporting is set to true. What have i missed? This should be simple
After rebooting my system, i was still not able to access the link correctly. Checked laravel.log file and nothing pointed to the issue in it. However i was able to fix this by creating another controller and everything worked perfectly. Still don't know why i had issues though.

button redirecting to wrong path

I am using a link button in my blade view. The code is as follows:
<a href="conclusion" class='btn btn-default btn-sm'>End Case</a>
The url of the page on which this link button is:
http://localhost/cases/137/responses/30
The result of my button should be
http://localhost/cases/137/responses/30/conclusion
but it is redirecting to
http://localhost/cases/137/responses/conclusion
My laravel route definition is:
get('/cases/{id}/responses/{respId}/conclusion', 'HomeController#conclusion');
What is wrong with it? How can I do it?
The save way to generate URLs is to always use Laravels helper functions. This way you don't have any problem with relative URLs as it always generates a full URL. In your case action() would be appropriate:
<a href="{{ action('HomeController#conclusion', [$id, $respId]) }}" class='btn btn-default btn-sm'>End Case</a>
Alternatively you can give your route a name:
get('/cases/{id}/responses/{respId}/conclusion', [
'as' => 'conclusion',
'uses' => 'HomeController#conclusion'
]);
And then:
<a href="{{ route('conclusion', [$id, $respId]) }}" class='btn btn-default btn-sm'>End Case</a>
Redirecting is not relative to the current path. Its relative to the index.xxx. I suggest that you use a fully qualified path.
The issue is the current url is pointing to a document, not a folder: https://cdivilly.wordpress.com/2014/03/11/why-trailing-slashes-on-uris-are-important/
When using relative href's you actually point to a document in the current folder. While your current url has no ending slash (/) it's interpreted as a document and the relative url will actually replace the document name.
So at this time you are pointing to the document conclusion in the folder http://localhost/cases/137/responses/, because 30 is also "just" a document in that folder.
In order to fix your problem you should hit your page as a folder http://localhost/cases/137/responses/30/ which allows for relative url's href="conclusion" to point to http://localhost/cases/137/responses/30/conclusion
To ensure this works in laravel, your route that points to the response should have an ending /. An even better solution would be to generate the route to the pages using the laravel helper functions like route() and action(); see http://laravel.com/docs/5.0/helpers#urls

Codeigniter URL for navigation

I can't figure out how to do the url links.
Basically I have my navigation bar, and I don't know which CodeIgniter URL code to use and how to implement it.
Is what I'm doing here right?:
<?php $this->load->helper('url'); ?>
<li>About Us</li>
I tried to do an anchor like this, but when I load the page it just turns up blank:
<?php echo anchor('views/about.html', 'About Us', title='About Us'); ?>
What am I doing wrong?
There are two ways to make links:
CodeIgniter helper style:
<?php echo anchor('about', 'About us', 'title="About us link"'); ?>
More common HTML with URL echo:
About us
Both will output:
About us
Though if I understand what you are trying to achieve, your mistake is elsewhere.
You don't include the views part, as your URL should point to the controller, not a view. The only case is if you have a controller named views.
CodeIgniter is set up so that it doesn't include file extensions like .html in URL's by default. It does if you've set them up in your config file in $config['url_suffix'] = '';, which is null by default.
See if you've made any of these mistakes.
That is another way on how you do the URL if you are using the URL helper in CI. You should try this, make the base_url() as the value for href. Try this,
About Us
You have to try like this
About Us
or you can give like
About Us
and in the "about" function you put
$this->load->view('about');
but i think the firstone will works for you fine.

CodeIgniter view anchor tag prepending host

In my view I'm trying to create an anchor tag but CodeIgniter is prepending my entire host before what I specify as href, therefor making it invalid.
I put this
My File
I get
My File
EDIT 3
This is my view, I realise i should not be calling a function in my view but in this case I had little option as something needs to get applied for each data item in the loop, I will try to change this but thats beyond my problem right now.
Wesley: I checked the soruce and it displays correctly in the source but in the browser it preappends the host so I guess this has nothing to do with code igniter afterall! How do I make sure it doesn't happen?
<td><?php
$this->ci = &get_instance();
echo $currentData["field_one"] . " - Log"; ?>
</td>
EDIT 4
my html source
<a href="file:://///\\myhost.local.com\120">
View Log
</a>
my url address bar
http://myhost.local.com/myhostlocal/index.php/level/one/type/b/cc/ee/
the url it goes too when I mouse over the href
http:///myhostlocal/index.php/level/one/type/b/cc/ee/file:://///\\myhost.local.com\120
Looks like the browser is treating "file:://///" as a relative path. Why do you have 2 colons, do you need both? Removing one will provide a valid protocol, and the browser will start treating it as an absolute path.

Resources