why PDO crashes if initialized in another php file? - pdo

I have this PDO object called "dbv". I initialize it in my config.php included file. It gives the error:
"Fatal error : Call to a member function prepare() on null".
After a few refreshes, it also said:
"Notice: Undefined variable: dbv"
But it would not say something like
"failed to open stream config.php"
If I cut all inside the config.php file and paste it directly above my $dbv->prepare() function, inside drawHeader() from sections.php, it works fine.
How can I make it work initializing my PDO inside config.php?
I have 3 files:
php/config.php (where I initialize the PDO)
php/sections.php (where I have my drawHeader() with the pdo->prepare() function that fails)
main.php (my main page that I open in the browser)
Here is my code:
config.php:
<?php
$database="dbname";
$username="dbuser";
$password="dbpass";
$dbv=new PDO("mysql:host=localhost;port=3308;dbname=".$database,$username,$password);
?>
sections.php:
<?php
function drawHeader() {
if (!isset($_SESSION["LIMBA"])) {
$_SESSION["LIMBA"]="ro";
}
$limba=$_SESSION["LIMBA"];
echo '
<!DOCTYPE html>
<html lang="'.$limba.'">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Roboto+Condensed:wght#300&display=swap" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="css/stylesheet.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<title>My title</title>';
$query="SELECT * FROM pagini_statice WHERE URL=?";
$stmt=$dbv->prepare($query);
$stmt->bindValue(1, $_SESSION['URL']);;
$stmt->execute();
$pag=$stmt->fetch();
echo $pag["CSS"];
//the rest of the code .....
main.php:
<?php
include("php/config.php");
include_once("php/sections.php");
session_start();
$_SESSION["URL"]="pagina.php";
drawHeader();
drawFooter();
?>

You need to require/include the config.php file, like:
<?php
require_once 'your/path/to/config.php';
function drawHeader() {
if (!isset($_SESSION["LIMBA"])) {
$_SESSION["LIMBA"]="ro";
}
$limba=$_SESSION["LIMBA"];
echo '
<!DOCTYPE html>
<html lang="'.$limba.'">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Roboto+Condensed:wght#300&display=swap" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="css/stylesheet.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<title>My title</title>';
$query="SELECT * FROM pagini_statice WHERE URL=?";
$stmt=$dbv->prepare($query);
$stmt->bindValue(1, $_SESSION['URL']);;
$stmt->execute();
$pag=$stmt->fetch();
echo $pag["CSS"];

Related

Vue js change structure dist

I need to change the structure of my files when I put in production :
default :
-dist
--css
--fonts
--img
--js
--favicon.ico
--index.html
and i want like this :
-dist
--index.html
--app
---css
---fonts
---img
---js
---favicon.ico
I try to change directly the html in index.html
<!doctype html>
<html lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="icon" href="app/favicon.ico">
<title>Roquette</title>
<script defer="defer" src="app/js/chunk-vendors.6e8aa085.js"></script>
<script defer="defer" src="app/js/app.4955a200.js"></script>
<link href="app/css/app.d0b83381.css" rel="stylesheet">
</head>
<body>
<noscript><strong>We're sorry but serveur-roquette doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div>
</body>
</html>
But it doesn't work there must be some paths missing somewhere

I got 'is not defined' when trying to access class from a CDN loaded on Vue js

While trying to use Twilio TaskRouter JS SDK on Vue JS, that you have load through CDN.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
<script src="https://sdk.twilio.com/js/taskrouter/v1.21/taskrouter.min.js" integrity="sha384-5fq+0qjayReAreRyHy38VpD3Gr9R2OYIzonwIkoGI4M9dhfKW6RWeRnZjfwSrpN8" crossorigin="anonymous"></script>
</body>
</html>
I want to init my worker like this:
export const initWorker = (token) => {
return new Twilio.TaskRouter.Worker(token);
}
but it's giving me this error: 'Twilio' is not defined. but it's actually working and returning the Worker object. is there way to ignore or to say Vue js that I'm expecting Twilio?
Found a fix, you have to tell eslint that you'll have this as global, there are two ways to go:
add this before your variable call:
/* global Twilio */
or edit your eslint config:
'globals': {
'Twilio': 'readable'
},

Phalcon: how to require a .php file in my volt file?

I am using Phalcon for the 1st time and I would like to migrate the content of an index.php file from my website into the index.volt file (in app/views).
So I tried to use require 'header.php' that I normally use in my index.php in the index.volt, like so:
index.volt
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Phalcon PHP Framework</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="../../public/css/index.css">
</head>
<?php require 'layouts/header.php' ?>
<body onload="document.body.classList.add('loaded')" id="cool">
<div class="container-fluid" style="height: 400px;">
{{ content() }}
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyA-5rrW4FY43z63mHhwpv7BIZE3bv8Ws_A&libraries=places"></script>
<script type="text/javascript" src="../../public/js/index.js"></script>
</body>
</html>
But I get this error:
Warning: require(layouts/header.php): failed to open stream: No such
file or directory in
C:\xampp\htdocs\care\cache\c__xampp_htdocs_care_app_views_index.volt.php
on line 14
Fatal error: require(): Failed opening required 'layouts/header.php'
(include_path='C:\xampp\php\PEAR') in
C:\xampp\htdocs\care\cache\c__xampp_htdocs_care_app_views_index.volt.php
on line 14
So is there a particular way to include php file with phalcon ?
Thank you

Angular Routing not working - blank screen

I am stymied by this issue. For some reason the Angular routing is not working at all. I simply get a blank screen. All of the modules are loading, there is no error in the console, and if I enter Angular in the console, it works. Yet, I get a blank screen.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>QuickCalcs</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/main.css" rel="stylesheet">
<link rel="stylesheet" href="css/ng-animation.css">
<script src="js/jquery-1.11.1.min.js"></script>
<script src="js/angular.js"></script>
<script src="js/bootstrap.js"></script>
<script src="js/angular-route.min.js"></script>
<script src="js/angular-animate.min.js"></script>
<script src="js/app.js"></script>
<script src="js/factories.js"></script>
<script src="controllers/qcController.js"></script>
</head>
<body ng-app="qc">
<div ng-view></div>
</body>
</html>
-----------------------------
app.js file is:
-----------------------------
var qc = angular.module('qc', [
'ngRoute',
'ngAnimate',
'ngResource'
]);
qc.config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/', {
templateUrl: 'views/home.html',
controller: 'qcController'
}).
when('/home', {
templateUrl: 'views/home.html',
controller: 'qcController'
}).
when('/results', {
templateUrl: 'views/results.html',
controller: 'qcController'
}).
otherwise({
redirectTo: 'views/home.html'
});
}]);
-----------------------------
Directory structure is:
-----------------------------
qc
/js
app.js
/views
home.html
results.html
/controllers
qccontroller.js
You must link your page to the application module
in the html tag like this:
< html lang="en" ng-app="qc" />

YiiBooster theme not working

i'm newbie to yii & i'm trying to install booster as well described in the home page but without sucess.
the extension works, i generated CRUDs using 'bootstrap.gii' but i steel having the classic blueprint theme. there is my view output :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="language" content="en" />
<!-- blueprint CSS framework -->
<link rel="stylesheet" type="text/css" href="/thouraya_booster/css/screen.css" media="screen, projection" />
<link rel="stylesheet" type="text/css" href="/thouraya_booster/css/print.css" media="print" />
<!--[if lt IE 8]>
<link rel="stylesheet" type="text/css" href="/thouraya_booster/css/ie.css" media="screen, projection" />
<![endif]-->
<link rel="stylesheet" type="text/css" href="/thouraya_booster/css/main.css" />
<link rel="stylesheet" type="text/css" href="/thouraya_booster/css/form.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="/thouraya_booster/assets/b50f179f/css/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="/thouraya_booster/assets/b50f179f/css/bootstrap-responsive.css" />
<link rel="stylesheet" type="text/css" href="/thouraya_booster/assets/b50f179f/css/bootstrap-yii.css" />
<link rel="stylesheet" type="text/css" href="/thouraya_booster/assets/b50f179f/css/jquery-ui-bootstrap.css" />
<script type="text/javascript" src="/thouraya_booster/assets/f74bdb93/jquery.js"></script>
<script type="text/javascript" src="/thouraya_booster/assets/b50f179f/js/bootstrap.bootbox.min.js"></script>
<script type="text/javascript" src="/thouraya_booster/assets/b50f179f/js/bootstrap.js"></script>
<title>My Web Application</title>
</head>
i tried to add manually the bootsrtap theme as it use to be with chris's bootstrap extention but i'm getting this error message Bootstrap and its behaviors do not have a method or closure named "register".
i tried to manually modify the layouts/main.php exchanging the blueprint loading css by <?php echo Yii::app()->bootstrap->registerCoreCss(); ?> but it dosn't work
i even tried a chmod777 for if access is denied to some css file and the extension is then replacing it by the yii's default one.
here is how my config file looks like:
...
// preloading 'log' component
'preload'=>array(
'log',
'bootstrap',
),
// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',
),
'modules'=>array(
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'root',
// If removed, Gii defaults to localhost only. Edit carefully to taste.
'ipFilters'=>array('127.0.0.1','::1'),
'generatorPaths' => array(
'bootstrap.gii'
),
),
),
// application components
'components'=>array(
'bootstrap' => array(
'class' => 'ext.bootstrap.components.Bootstrap',
'responsiveCss' => true,
),
...
I don't know if i'm missing something somewhere.
I had the exact same problem, here is how I solved it:
I created a new clean webapp (using yiic webapp) and installed YiiBooster as you have
Get YiiBoilerplate and unzip it somewhere
Go to {unzipped}backend/views/layouts/ and grab main.php, column1.php and column2.php
create a new theme in your webapp under the /themes folder (I called it 'booster')
Copy the three files from (3) into themes/booster/views/layouts
In your main.php add 'theme' => 'booster' as a top-level entry of the array (I put it first)
P.S. Love your Avatar...
In file views/layouts/main.php delete in HEAD Yii::app()->bootstrap->register();
I got simpler, step-by-step method:
Extract yiibooster to extensions folder and rename the folder into "yiibooster"
Add the following code in /protected/config/main.php
Yii::setPathOfAlias('booster', dirname(__FILE__) . DIRECTORY_SEPARATOR . '../extensions/yiibooster');
Still in the /protected/config/main.php components add:
'bootstrap' => array(
'class' => 'booster.components.Bootstrap',
),
In any controller I want to use YiiBooster widgets, just put the following code:
public function filters()
{
return array(
array('booster.filters.BootstrapFilter - delete')
);
}
And thats it! Now Try to put some button in your view, for example:
$this->widget(
'booster.widgets.TbButton',
array(
'label' => 'Primary',
'context' => 'primary',
)
);
Trust me, this really works. I've applied it to my project.
Source:
http://www.yiiframework.com/forum/index.php/topic/52918-yiibooster-installation-steps/