CI 3 requested url not found - codeigniter

I'm new in CI 3. I want to view another page when the button is clicked. I'm using Wamp server. in my root folder (www) I name my project sampleproject.
In my routes.php
$route['default_controller'] = 'user';
Controller file name is User.php
public function login_user(){
$this-load-view('welcome_message');
}
And in my view
<form action="/user/login_user" method="POST" role="form">
<button class="btn btn-primary btn-block">Login</button>
</form>
When I click the button in the URL it shows http://localhost/user/login_user
http://localhost/sampleproject -> show the index but when I enter http://localhost/sampleproject/user/login_user -> says requested URL not found.
Why can't I view another page?

In APPPATH.'config/config.php' you should set
$config['base_url'] = 'http://localhost/sampleproject/'
Eventually, in .htaccess file:
RewriteBase /sampleproject/

Related

Laravel route returning error 404 when attempt is made to pass value to controller function

I have a button in my blade like this
#can('customer_show')
<a class = "btn btn-primary" href = "{{ route('admin.loan-applications.showCustView', $loanApplication->user_id) }}">
View Applicant
</a>
#endcan
And this is the route:
Route::get('loan-applications/{loan_application}/showCustView', 'loanApplicationsController#showCust')->name('loan-applications.showCustView');
And in my controller, i did:
public function showCust(LoanApplication $loanApplication)
{
$customerInformation = customerInfoModel::where('Cust_id', $loanApplication->user_id));
return view('admin.loanApplictions.showCustView', compact(['customerInformation', 'loanApplication']));
}
What i am trying to do is fetch the row from the database attached to customerInfoModel where the the Cust_id field equals the loanApplication->user_id of the loan being viewed currently in the blade above. When the button "view Applicant" is hit, i get an error 404 page. Why is that so?
Check it out the route list using this command
php artisan route:list
//this command will show all the routes in your application
If your route not listed on that route list checkout for routes with same Url on your route manually on routes file.
if you found change the url & use this command to clear cache
php artisan optimize:clear
i have found the comment of you on last answer.
check out for route model binding . i think you have to add
a
public function showCust( $loanApplicationCustId)
{
$customerInformation = customerInfoModel::where('Cust_id', $loanApplicationCustId))->first();
return view('admin.loanApplictions.showCustView', compact(['customerInformation', 'loanApplication']));
}
It should be like this .. i hope it works for you......
else share your project git repo link
I think it should be like following:
#can('customer_show')
<a class = "btn btn-primary" href = "{{ route('loan-applications.showCustView', $loanApplication->user_id) }}">
View Applicant
</a>
#endcan
try that

problem in delete from pivot table in laravel

i have a problem in delete an order:
here the form where press on cancel to delete the order:
<form action="{{route('user.orders.delete', $order->id)}}" method="POST"
onsubmit="return confirm('Are you sure?');">
#method('DELETE')
#csrf
<button
type="submit" class="mt-8 mb-4 py-2 px-14 rounded-full
bg-red-900 text-white tracking-widest hover:bg-blue-800
transition duration-200">
Cancel
</button>
</form>
this is my router:
Route::delete('user/orders/delete/{order}', [OrderController::class, 'delete'])->name('user.orders.delete');
OrderController : delete function:
public function delete(Order $order)
{
try {
unlink(public_path().'/storage/orders/files/'.$order->file);
$order->delete();
}catch(\Exception $e) {
return redirect()->back()-with('status', 'you cannot delete this item');
}
return redirect()->back()->with('status', 'product deleted succefully');
}
so when click on the button (cancel) just go to the right url : when 21 is the order id
http://127.0.0.1:8000/user/orders/delete/21
and it is just not found page!!! and nothing deleted!!!
i think your app routes is cached
try to run the fallowing command (in cmd or terminal) to see all the routes, this will show registered routes and errors if exist:
php artisan route:list
if the route doesnt exist in route list, the route list may be cached. try the fallowing command to clear route cache:
php artisan route:clear
and then run app and test the route.
If you do not have another problem in coding or naming variables, the program will be fixed properly
*if all o the above is ok, it seems your apache config is not configure to delete request(for route delete method ) and you must change .htaccess requests LIMIT like the fallowing sample to Grant delete request :
<Limit GET POST PUT DELETE>
Allow from all
</Limit>
As you can see the DELETE method(request) has been added to .htaccess

How to create custom page before visit to store in Magento

I am working on Magento website where Client wants that there should be a custom login page with only 2 fields username and password.That username and password is different as customer's registration.That will be static say username as abc and password as xyz.
When any one visit the site then he need to enter the username and pasword ony then he can view the store.
How can I do this?
You can use basic access authentication with set .htpasswd
You can move magento to subdirectory and place in root folder index.php with setting cookies
You can make own module and overwrite index controller (harder way)
You can add some code to magento's index.php that verifies if isset cookie's value (simpler way)(with a backup of original index.php):
<?php
if (!isset($_COOKIE['auth1'])){
if(!isset($_POST['prelogin']) and !isset($_POST['prepass'])){
//your form to post
?>
<h1>Authentication Required</h1>
<form method=post>
<input type=text id=prelogin name=prelogin value=login>
<input type=text id=password name=password value=password>
<input type=submit value=submit>
</form>
<?php
} else { //isset $_POST
//...
//your login+password check code
//...
setcookie("auth1", "your_md5(md5(pass))", time()+60*60*24*100, "/");
header( 'Location: /index.php', true, 303 );
}
} else { //isset $_COOKIE['auth1']
//...
//other $_COOKIE['auth1'] checks here
//....
//main magento code
}
?>
Next make diff patch with
diff -u index.php.bak index.php > auth.patch
And after You upgrade your magento version simply launch
patch index.php < auth.patch

Unexpected URI segment in codeigniter

I am accessing user profile page with this type of url
foo.com/index.php/controller/view_profile/user_id
its working fine. In the profile page I have different segement of the profile and using buttons for them.
if I click on a button which should take me to user financial data, its redirects to
foo.com/index.php/controller/view_profile/user_finance/user_id
instead of
foo.com/index.php/controller/user_finance/user_id
in the button link i just used following code
echo '<button class="btn btn-info btn-large">Financial Information</button>';
What am I doing wrong? Thanks in advance.
Please use the following to generate the code for the link.
$array = array(
'class' => '<button class="btn btn-info btn-large">'
);
echo anchor('controller/user_finance/' . $user_id,"Financial Information",$array);
EDIT:
The above link you are using wont work as it needs full url which anchor helper will generate.

refresh page with joomla component

I have a simple form in my tmpl/default.php:
<form id='AddForm' action="<?php echo JRoute::_('index.php?option=com_mycomponent&task=addcam'); ?>" >
<p>
<label for="CamName">Name:
</label>
<input type="text" id="CamName" name="cam_name" />
</p>
<button type='submit' class='submit_cam' name='addcam' value='Add'>Add</button>
<button type='reset' class='cancel_changes' name='cancel_changes' value='Cancel'>Cancel</button>
</form>
In my controller.php file I'm trying to process the values:
function addcam()
{
$add_name=JRequest::getString('cam_name');
$model = &$this->getModel();
$model->AddWebcam($add_name); //send to model to add to DB
}
In my model I just return the result of the query. With this implementation I just get routed to an empty page. I'd like to have it refresh the current page. Typically you do this with action="" but in my case I need it to route to the function called addcam in the controller. Or is there a better way to do this?
A common technique in Joomla when directing to the task is to have that function do a full redirect to a view at the end. This prevents a page refresh from trying to resubmit the data and leads to a cleaner url for the client. To do this, try the following:
function addcam()
{
$add_name=JRequest::getString('cam_name');
$model = &$this->getModel();
$model->AddWebcam($add_name); //send to model to add to DB
JFactory::getApplication()->redirect(JRoute::_(index.php?option=com_mycomponent&view=whatever));
}
Obviously, update the JRoute bit to the url you actually need. You can also include a message if you would like (like "Saved!"): http://docs.joomla.org/JApplication::redirect/1.6

Resources