3
votes

I am working on a project in php Phalcon.

I am working with the Xampp server. The installation process that I followed is on this link:

http://docs.phalconphp.com/en/latest/reference/install.html

I am following the documentation on the website as guide and tutorial.

My problem is, every time I type "class MyClass extends \Phalcon\Mvc\Model"

it says undefined namespace "Mvc" and in other files it also gives error that Phalcon is an undefined namespace.

The installation seems okay.

Please help me out.

3
If it's not working the installation is definitely not OK. But there's really no way to tell what exactly is wrong. - Jon
So what can i do? reinstall? is there any other option? - Rabbiya Shahid
As jumper85 noted it's an IDE "issue". Whatever editor you're working in doesn't know Phalcon libraries so it is only referring to standard PHP libraries and everything else is unrecognized. Just ignore "errors". If code works in the browser thats what you care about. Codelobster PHP editor has a paid Phalcon plugin. - ed-ta

3 Answers

3
votes

I think this is not really a problem with the installation of Phalcon.

I have recognized the same behaviour of my IDE because Phalcon is only loaded as an extension of PHP and not available as real PHP files which can be indexed by your IDE.

The easiest way to check if install was ok is to create a info.php in your project root.

<?php
phpinfo();

If you open this file in browser it should show a block with information about phalcon.

There is a script that creates stub files for you that can be integrated in you project.

https://github.com/phalcon/phalcon-devtools/blob/master/ide/gen-stubs.php

If these files are indexed by your IDE, the message of Undefined namespace should be gone.

1
votes

If your code works. And IDE shows Mvc undefined namespace then you have to install Phalcon developer tool plugin for your IDE. the plugin is available for PHPStorm. Phalcon is a C extention and for this if you not install developer tool plugin then IDE will show undefined namespace.

Phalcon has different ways to use model like register model class, register namespace or register dir. If you create the model by command rather than manually write code you will get the proper base model class to extend. If still problem then there is problem with Phalcon installation.

Use --namespace="" for model:

phalcon create-model profiles --namespace="Application\Models"

For scaffold:

phalcon create-scaffold profiles --ns-models="Application\Models" --ns-controllers="Application\Controllers"

If you do not register the model namespace and register only model directory then edit the model file after creation and remove the namespace definition.

0
votes

first check if php load phalcon module. for that in terminal type

php -r "echo phpinfo();" | grep 'phalcon'

if everything went write you should see line

phalcon => enabled

in windows grep wont work and you should look for that line yourself.