I downloaded Phalcon from official website
I copied php_phalcon.dll file to my xampp's php/ext directory
Edited the php.ini file located at D:\xampp\php\php.ini. and add there line extension=php_phalcon.dll at the end of the file.
I Restarted apache server and computer several times.
When I write phpinfo() to my code it seems phalcon was installed
Unfortunatelly Whan I try to run some code like
<?php
try {
// Autoloader
$loader = new \Phalcon\Loader();
$loader->registerDirs([
'../app/controllers/',
'../app/models/'
]);
$loader->register();
// Dependency Injection
$di = new \Phalcon\DI\FactoryDefault();
$di->set('view', function() {
$view = new \Phalcon\Mvc\View();
$view->setViewsDir('../app/views');
return $view;
});
// Deploy the App
$app = new \Phalcon\Mvc\Application($di);
echo $app->handle()->getContent();
} catch(\Phalcon\Exception $e) {
echo $e->getMessage();
}
?>
I get this error
Fatal error: Uncaught Error: Class 'Phalcon\Loader' not found in D:\xampp\htdocs\php-learning\public\index.php:4 Stack trace: #0 {main} thrown in D:\xampp\htdocs\php-learning\public\index.php on line 4
I also tried to follow the steps from tutorial on Phalcon ofical website where code looks somehow like this
<?php
use Phalcon\Di\FactoryDefault;
use Phalcon\Loader;
use Phalcon\Mvc\View;
use Phalcon\Mvc\Application;
use Phalcon\Url;
// Define some absolute path constants to aid in locating resources
define('BASE_PATH', dirname(__DIR__));
define('APP_PATH', BASE_PATH . '/app');
// Register an autoloader
$loader = new Loader();
$loader->registerDirs(
[
APP_PATH . '/controllers/',
APP_PATH . '/models/',
]
);
$loader->register();
$container = new FactoryDefault();
$container->set(
'view',
function () {
$view = new View();
$view->setViewsDir(APP_PATH . '/views/');
return $view;
}
);
$container->set(
'url',
function () {
$url = new Url();
$url->setBaseUri('/');
return $url;
}
);
$application = new Application($container);
try {
// Handle the request
$response = $application->handle(
$_SERVER["REQUEST_URI"]
);
$response->send();
} catch (\Exception $e) {
echo 'Exception: ', $e->getMessage();
}
But didnĀ“t help. What I am doing wrong?
You have Phalcon installed successfully. However the namespace should be changed:
Moved Phalcon\Loader to Phalcon\Autoload\Loader #15797
please refer to the change log
enter link description here
Related
I'm just getting started with PHP and I ran into a small problem.
I've downloaded a package using composer require <package_name> and now I'm not sure how to access it from my .php file. I tried bunch of things but I couldn't make it work.
I'm trying to use this package: https://packagist.org/packages/giggsey/libphonenumber-for-php
EDIT:
This is the code I use to test:
<?php
use Slim\Factory\AppFactory;
require __DIR__ . '/../vendor/autoload.php';
// Instantiate app
$app = AppFactory::create();
// Add Error Handling Middleware
$app->addErrorMiddleware(true, false, false);
// Register routes
$routes = require __DIR__ . '/../app/routes.php';
$routes($app);
$swissNumberStr = "044 668 18 00";
$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
try {
$swissNumberProto = $phoneUtil->parse($swissNumberStr, "CH");
var_dump($swissNumberProto);
} catch (\libphonenumber\NumberParseException $e) {
var_dump($e);
}
// Run application
$app->run();
And it says: Undefined type 'libphonenumber\PhoneNumberUtil'.
index.php
require "vendor/autoload.php";
require "routes.php";
routes.php
<?php
require "vendor/autoload.php";
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Generator\UrlGenerator;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
try {
$form_add_route = new Route(
'/blog/add',
array(
'controller' => '\HAPBlog\Controller\EntityAddController',
'method'=>'load'
)
);
$routes = new RouteCollection();
$routes->add('blog_add', $form_add_route);
// Init RequestContext object
$context = new RequestContext();
$context->fromRequest(Request::createFromGlobals());
$matcher = new UrlMatcher($routes, $context);
$parameters = $matcher->match($context->getPathInfo());
// How to generate a SEO URL
$generator = new UrlGenerator($routes, $context);
$url = $generator->generate('blog_add');
echo $url;
}
catch (Exception $e) {
echo '<pre>';
print_r($e->getMessage());
}
src/Controller/EntityAddController.php
<?php
namespace HAPBlog\Controller;
use Symfony\Component\HttpFoundation\Response;
class EntityAddController {
public function load() {
return new Response('ENTERS');
}
}
I am referring to the tutorial given below:
https://code.tutsplus.com/tutorials/set-up-routing-in-php-applications-using-the-symfony-routing-component--cms-31231
But when I try to access the site http://example.com/routes.php/blog/add
It gives a blank page.
Debugging via PHPStorm shows that it does not enter "EntityAddController" Class
What is incorrect in the above code ?
There is no magic behind this process, once you get the route information, you will have to call the configured controller and send the response content.
Take a complete example here:
// controllers.php
class BlogController
{
public static function add(Request $request)
{
return new Response('Add page!');
}
}
// routes.php
$routes = new RouteCollection();
$routes->add('blog_add', new Route('/blog/add', [
'controller' => 'BlogController::add',
]));
// index.php
$request = Request::createFromGlobals();
$context = new RequestContext();
$context->fromRequest($request);
$matcher = new UrlMatcher($routes, $context);
try {
$attributes = $matcher->match($request->getPathInfo());
$response = $attributes['controller']($request);
} catch (ResourceNotFoundException $exception) {
$response = new Response('Not Found', 404);
} catch (Exception $exception) {
$response = new Response('An error occurred', 500);
}
$response->send();
I want to integrate ckfinder with my laravel but I am stuck with authentication.
I found many ways but there were for older laravel versions and none are working for 5.6.
I found this:
require '../../vendor/autoload.php';
$app = require_once '../../bootstrap/app.php';
$app->make('Illuminate\Contracts\Http\Kernel')
->handle(Illuminate\Http\Request::capture());
But I am getting Invalid request from Ckfinder when I put it in config.php
I would like to access Auth::check() and return it in authentication
require __DIR__ . '/../../vendor/autoload.php';
$app = require_once __DIR__ . '/../../bootstrap/app.php';
$request = Illuminate\Http\Request::capture();
$request->setMethod('GET');
$app->make('Illuminate\Contracts\Http\Kernel')
->handle($request);
$config['authentication'] = function () {
return auth()->check();
};
EDIT
So I had a look at index.php and copied this into config.php:
define('LARAVEL_START', microtime(true));
require '/Applications/MAMP/htdocs/laravel-dealer/vendor/autoload.php';
$app = require_once '/Applications/MAMP/htdocs/laravel-dealer/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
But I am getting runtime exceptions for $acl argument.
Fatal error: Uncaught RuntimeException: Controller
"CKSource\CKFinder\Command\Init::execute()" requires that you provide
a value for the "$acl" argument. Either the argument is nullable and
no null value has been provided, no default value has been provided or
because there is a non optional argument after this one. in
/Applications/MAMP/htdocs/laravel-dealer/vendor/symfony/http-kernel/Controller/ArgumentResolver.php:78
Stack trace: #0
/Applications/MAMP/htdocs/laravel-dealer/vendor/symfony/http-kernel/HttpKernel.php(141):
Symfony\Component\HttpKernel\Controller\ArgumentResolver->getArguments(Object(Symfony\Component\HttpFoundation\Request),
Array) #1
/Applications/MAMP/htdocs/laravel-dealer/vendor/symfony/http-kernel/HttpKernel.php(66):
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request),
1) #2
/Applications/MAMP/htdocs/laravel-dealer/public/ckfinder/core/connector/php/vendor/cksource/ckfinder/src/CKSource/CKFinder/CKFinder.php(610):
Symfony\Component\HttpKernel\HttpKernel- in
/Applications/MAMP/htdocs/laravel-dealer/vendor/symfony/http-kernel/Controller/ArgumentResolver.php
on line 78
Thanks for any help
Here's how the authentication section looks like on one of my projects
/*============================ Enable PHP Connector HERE ==============================*/
// http://docs.cksource.com/ckfinder3-php/configuration.html#configuration_options_authentication
require __DIR__ . '/../../vendor/autoload.php';
$app = require_once __DIR__ . '/../../bootstrap/app.php';
$request = Illuminate\Http\Request::capture();
$request->setMethod('GET');
$app->make('Illuminate\Contracts\Http\Kernel')
->handle($request);
$config['authentication'] = function () {
return auth()->check();
};
Well I spent some time with this and came up with this solution:
This function gets the value of $_COOKIE['allowCkfinder'] and decrypts it using cipher and your app key.
// /public/ckfinder/config.php
$config['authentication'] = function () {
$APP_KEY = "YOUR_APP_KEY";
$cookie_contents = json_decode( base64_decode( $_COOKIE['allowCkfinder'], true ));
$value = base64_decode( $cookie_contents->value );
$iv = base64_decode( $cookie_contents->iv );
return unserialize( openssl_decrypt($value, "AES-256-CBC", base64_decode($APP_KEY), OPENSSL_RAW_DATA, $iv));
};
When logging in user / admin set cookie with name allowCkfinder:
Also dont forget to remove the cookie on user logout.
// /app/Http/Controllers/LoginController.php
if (Auth::attempt(['user_email' => $validatedData['email'], 'password' => $validatedData['password'], "user_active" => 1, "user_banned" => 0]))
{
if (Auth::user()->user_admin == TRUE)
return redirect()->intended('/')->withCookie(cookie()->forever('allowCkfinder', "1"));
else
return redirect()->intended('/');
} else
{
$request->session()->flash('error', __("E-mail and/or password do not match"));
return redirect('login')->withInput();
}
That's the best I came up with.
i have uploaded my laravel project to live server but its not working when i track code i get the execption that class request does not exists,please help me to find out the error
this is my file
index.php
<?php
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
$app->bind('path.public', function() {
return __DIR__;
});
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
try{
$request = App\Http\Request::capture()
}
catch(Exception $e)
{
echo "error:".$e->getMessage()."<br>";
}
$response = $kernel->handle(
$request = App\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);
Request facade usually lives in a different namespace. Try replacing any reference to
App\Http\Request
with just
Request
in order to access the facade by its global namespace alias.
I am new in fbdevelopment, so I downloaded php sdk 4 and extated in component with name facebook-sdk and then I configured in main.php
as
'import'=>array(
'application.models.*',
'application.components.*',
'application.components.facebook-sdk.*',
Then in my site controller I want to call:
$session = new FacebookSession($_POST['accessToken']);
But even thought I have an access token, it returns:
include(FacebookSession.php): failed to open stream: No such file or directory
where we have to configuration php-sdk 4 in yii
I had this problem like you and it took me hours to debug. Finally, I found that I missed the namespace "Facebook\" before the class name.
Here is my code it works well:
require_once 'facebook-php-sdk/autoload.php';
require_once 'facebook-php-sdk/src/Facebook/FacebookSession.php';
require_once 'facebook-php-sdk/src/Facebook/FacebookRequest.php';
require_once 'facebook-php-sdk/src/Facebook/GraphObject.php';
require_once 'facebook-php-sdk/src/Facebook/GraphUser.php';
require_once 'facebook-php-sdk/src/Facebook/FacebookSDKException.php';
require_once 'facebook-php-sdk/src/Facebook/FacebookRequestException.php';
Facebook\FacebookSession::setDefaultApplication(FACEBOOK_APP_ID, FACEBOOK_APP_SECRET);
$helper = new Facebook\FacebookRedirectLoginHelper('http://mywebsite.com');
try {
$session = $helper->getSessionFromRedirect();
} catch(Facebook\FacebookRequestException $ex) {
// When Facebook returns an error
} catch(\Exception $ex) {
// When validation fails or other local issues
}
if ( isset($session) ) {
// Logged in
$me = (new Facebook\FacebookRequest($session, 'GET', '/me'))->execute()->getGraphObject(GraphUser::className());
var_dump($me);
}
else {
$loginUrl = $helper->getLoginUrl();
header("Location: ".$loginUrl); exit;
}