blank page after changed link - smarty - php

I wanted to help a friend on his website and he told me to change a link. he use smarty and the website is online
so i change this
<li class="first">Le réseau</li>
to absolute path.
Now, i have this error
Fatal error: Call to undefined function reecrire_url() in /home/deflandrgb/www/includes/smarty/sysplugins/smarty_internal_filter_handler.php on line 60
But I have not changed anything except link.
why I have this error?
Thanks
ps: I handed the old link but I still have the same error
EDIT : i find this function in Site_Smarty.class.php
class Site_Smarty extends Smarty{
public function Site_Smarty(){
parent::__construct();
//$this->caching = true;
//$this->compile_check = true;
$this->template_dir = root.'templates/';
$this->compile_dir = root.'templates_c/';
$this->config_dir = root.'includes/smarty/';
$this->cache_dir = root.'cache/';
//$this->debugging = true;
$this->registerFilter('pre','reecrire_url');
$this->assign('app_name', 'Guest Book');
$this->assign('path', path);
}
}

Seems you missed to define the callback function "reecrire_url"
See docs:
http://www.smarty.net/docs/en/api.register.filter.tpl

Related

This happens only on live server: Fatal error: Uncaught Error: Call to a member function signin() on boolean in

Confession:
I read many similar questions on this platform, but nothing seems closely aligned to my situation. Most of the questions seem to originate from binding params in prepared statements or execute statement.
In my case, the website runs smooth on a local server(Apache2). However, it throws the error below when published on live server.
Fatal error: Uncaught Error: Call to a member function signin() on boolean in /storage/ssd5/815/17670815/app/controllers/signin.php:16 Stack trace: #0 /storage/ssd5/815/17670815/app/core/app.php(33): Signin->index() #1 /storage/ssd5/815/17670815/public_html/index.php(4): App->__construct() #2 {main} thrown in /storage/ssd5/815/17670815/app/controllers/signin.php on line 16
Context
I'm using MVC (OOP) in PHP and here the relevant parts mentioned in the error. I hope this is not too much.
In the main index page, the line referred in the error is a core class(App) instantiation
<?php
session_start();
require_once '../app/initializer.php';
$app = new App(); //this is the line 4 mentioned in the error
In Signin controller class the line referred in the error is indicated below
<?php
class Signin extends Controller{
function index(){
//you can do this if passing data to view
$data["Page_title"] = "Signin";
if($_SERVER['REQUEST_METHOD'] == "POST"){
// this is a debuggin code
//echo "I am signin controller <br />";
// show($_POST);
$user = $this->loadModel("User");
$user->signin($_POST); //this the line referred in the error
}
$this->view("zac/signin",$data);
}
}
In class APP the line is a callback - check below
<?php
class App {
private $controller = "home";
private $method = "index";
private $params = [];
public function __construct()
{
$url = $this->splitURL();
if(file_exists("../app/controllers/".strtolower($url[0]).".php")){
$this->controller = strtolower($url[0]);
//unset the array position
unset($url[0]);
}
require "../app/controllers/".$this->controller.".php";
// echo file_get_contents('http://smart-ecom.000webhostapp.com/app/controllers/'.$this->controller.".php");
//Create instance of whatever controller class is passed(if it exists, otherwise the home controller)
$this->controller = new $this->controller;
if(isset($url[1])){
if(method_exists($this->controller, $url[1])){
$this->method =$url[1];
unset($url[1]);
}
}
$this->params = array_values($url);
call_user_func_array([$this->controller, $this->method],$this->params); //this is line 33
}
/**
* splitURL gets url from browser and processes against the conroller classes and their methods
* #return array
*/
private function splitURL(){
//check if the the GET is set otherwise set the url to defualt class home
$url = isset($_GET['url']) ? $_GET['url'] :"home";
// return explode("/",filter_var(trim($_GET['url'],"/"), FILTER_SANITIZE_URL));
return explode("/",filter_var(trim($url,"/"), FILTER_SANITIZE_URL));
}
}
?>
The Database class's read function is as follows. This method isn't directly referred in the error message
public function read($query, $data = []){
$stmt = self::$conn->prepare($query);
$result = $stmt->execute($data);
if($result){
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
if(is_array($data) && count($data) > 0){
return $data;
}
}
return false;
}
As I mentioned earlier, this error fires on a live server but the website runs smooth in dev environment with PHP 7.4, Apache2, MySQL 8 Windows 10.
Your help is match appreciated in advance.
I learned this the hard way and I hope this can help someone with similar issues. The cause of the error because of how windows and Linux deals with case sensitivity in file names. In Windows, file names aren't case sensitive while in Linux - they are. So, that was the reason why the website was running smooth in the local dev environment(Windows machine) but throwing an error on a live server(which is Linux). To see the difference, refer to my earlier comment in this thread.
protected function loadModel($model){
if(file_exists("../app/models/". strtolower($model) . ".class.php")){
include "../app/models/".strtolower($model).".class.php";
return $model = new $model();
}else{
return false;
}
}
}
In the "include" line, you can see that I added the strtolower function to include the proper model and that solved the issue.

How do I solve this laravel layout issue?

My error: I am facing this issue quite long time and found one solution in stackoverflow but it doesn't work. I need solution to work with laravel , php 7+ and mysql.
It is showing below error:
ErrorException
Trying to get property 'app_layout' of non-object
Error page consists following code and i tried all solutions in stack overflow but no us. I want to show my layout without any error here.
Error in the script\app\Http\Controllers\MainBaseController.php:26
code on the page is : error line highlighted in BOLD below
use Illuminate\Support\Facades\Schema;
use Froiden\Envato\Traits\AppBoot;
class MainBaseController extends Controller
{
public function __construct()
{
parent::__construct();
// Settings
$this->settings = Setting::first();
$this->year = Common::year();
$this->bootstrapModalRight = true;
$this->bootstrapModalSize = 'md';
**$this->siteLayout = $this->settings->app_layout; // top, sidebar**
$this->forbiddenErrorView = 'errors.403';
$this->showFooter = true;
$this->rtl = $this->settings->rtl;
// Status
$this->statusArray = [
'enabled' => __('app.enabled'),
'disabled' => __('app.disabled')
];
// Setting assets path
$allPaths = Common::getFolderPath();
foreach($allPaths as $allPathKey => $allPath)
{
$this->{$allPathKey} = $allPath;
I am placing error part of the code above , if you need any other parts i will provide

Call to a member function searchActivityByName() on null

I am just working on my websites APIs, and when i tested it on localhost it seems to be working fine as it should be but when i uploaded it on the live server it gave me
error : Call to a member function searchActivityByName() on null.
My code is in the helper is :
function searchActivityByTitle($Actname,$persons=false,$price_filter=false,$time_filter=false,$limit = false, $offset = false) {
$ci =& get_instance();
//$Actname = !empty($Actname)?$Actname:"kite";
$data = $ci->ActivitiesModel->searchActivityByName($Actname, true, $persons, $price_filter, $time_filter,$limit, $offset);
if(!empty($data))
return array("data"=>$data["data"], "total_results" => $data["count"]);
else
return false;
}
Any help or suggestions would be appertiated, thanks in advance.
That usually happens in CI if the function can't be found because (1) the model/helper/library isn't loaded (2) the model/helper/library isn't loaded because it isn't named right.
Try loading the model in the function if it isn't already loaded/autoloaded before calling the helper function. Otherwise make sure the model is named correctly and defined correctly according to CI standards (on linux systems e.g. "live server"
this is usually the issue).
Standards:
model file: models/some_model.php
definition: class Some_model { }
load: $this->load->model('some_model'); $this->some_model->some_method();

CakePHP3 - Custom page error 404 not working

I doing tutorial follow http://book.cakephp.org/3.0/en/development/errors.html#exception-renderer but it is not working and display blank page.
In config/bootstrap.php
use App\Error\AppError;
$errorHandler = new AppError();
$errorHandler->register();
In src/Error/AppError.php
<?php
namespace App\Error;
use Cake\Error\BaseErrorHandler;
class AppError extends BaseErrorHandler
{
public function _displayError($error, $debug)
{
return 'There has been an error!';
}
public function _displayException($exception)
{
return 'There has been an exception!';
}
public function handleFatalError($code, $description, $file, $line)
{
return 'A fatal error has happened';
}
}
I create my_error.ctp in src/Template/Layout/my_error.ctp. And in my src/Template/Error/error404.ctp I change layout to my_error.ctp.
$this->layout = 'my_error';
Finally, In my controller
use Cake\Network\Exception\NotFoundException;
$staff = $this->Staff->find()->where(['Staff.StaffId = '=> $id, 'Staff.PartnerId = ' =>$this->partnerId])->first();
if (empty($staff)) {
throw new NotFoundException(__('Staff not found'));
}
Whenever encountering blank pages, enabled debug mode, visit the URL again, and check your error logs.
However, problem in this case is most likely that the docs are incorrect/misleading, as the example app error won't do anything at all. The _ prefixed methods are ment to be protected, having them return something has no effect, and handleFatalError is ment to return a boolean.
Just look at the source of Cake\Error\BaseErrorHandler and the core error handler Cake\Error\ErrorHandler, the methods that you are overwriting are ment to generate output!
You may want to report that as an issue over at GitHub.
If all you want to do, is create a custom 4xx error page, then all you need to do is to edit the src/Template/Error/error400.ctp template accordingly.
I found my mistake. :(
Because in bootstrap.php I copy below code at the end of file. Therefore Cake cannot understand it. Please close this issue. Thank you for support.
use App\Error\AppError;
$errorHandler = new AppError();
$errorHandler->register();

How To Use MVC PHP With Case Sensitive?

I am creating website in PHP. I am using MVC in PHP. My website works like this, if user go to example.com/about then it it will load About class and index() function. If user will go to localhost/about/founder then it will load founder() function from About class. but the thing is that if I go to localhost/About or localhost/AbOut or anything like that it is loading default index() function from About class file. So what to do with case sensitivity? I mean I want my script to load index() function from class file if it is localhost/about or localhost/terms. If anything is in uppercase, then it should load 404 error function. 404 error function is already set in my site.
Please help me friends.
here is my Bootstrap.php class file
<?php
/*
Bootstrap class to run functions by URL
*/
class Bootstrap {
public $_req;
public $_body;
public $_file;
public $_error;
function __construct(){
if(empty($_GET['req'])){
require 'classes/home.php';
$this->_body = new Home();
$this->hdr($this->_body->head());
$this->_body->index();
$this->ftr();
exit();
}
$this->_req = rtrim($_GET['req'], '/');
$this->_req = explode('/', $this->_req );
$_file = 'classes/'.$this->_req[0].'.php';
if(file_exists($_file)){
require $_file;
}
else {
$this->error(404);
}
$this->_body = new $this->_req[0];
$this->hdr($this->_body->head());
if(isset($this->_req[2])){
if(method_exists($this->_req[0], $this->_req[1])){
$this->_body->{$this->_req[1]}($this->_req[2]);
}else {
$this->error(404);
}
}else {
if(isset($this->_req[1])){
if(method_exists($this->_req[0], $this->_req[1])){
$this->_body->{$this->_req[1]}();
}else {
$this->error(404);
}
}else {
$this->_body->index();
}
$this->ftr();
}
}
//this function is to set header in html code
public function hdr($var = false){
echo '<!DOCTYPE HTML><html><head>'.$var.'</head><body>';
}
//this function is tp set footer in html code
public function ftr($var = false){
echo $var.'</body></html>';
}
//error handler
public function error($var){
require 'classes/er_pg.php';
$this->_error = new Error();
$this->_error->index($var);
}
}
You shouldn't use anything to load non-lowercase URLs because of the duplicate content, and that's a good thing you're doing. The wrong URLs should fail automatically in such cases.
However, since you didn't show how are you making those calls, then only thing I can suggest at this point is to check if the called method exists (case-sensitive), and if not, throw/redirect to a 404 page (header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");).
UPDATE
After all the chat in the comments, seems like file_exists is not case-sensitive in your case, which is really weird. Hopefully someone will be able to figure it out so I can delete this (keeping it because of the info in the comments).
I solved the problem. I used this
if(ctype_lower($this->_req[0])){
$_file = 'classes/'.$this->_req[0].'.php';
and now its working. Thanx anyways friends.

Categories