ERROR: Option namespace has't been defined
Questions should go to https://forum.phalconphp.com Documentation issues should go to https://github.com/phalcon/docs/issues
Expected and Actual Behavior
I'm currently trying to scaffold a table from my database. Just trying to follow some tutorial at first. (learnphalcon.com) and i get this error : "ERROR: Option namespace has't been defined"
after using this command :
phalcon scaffold Booking --get-set
WITH this table :
Create Table Booking
(
id integer auto_increment,
bookingdate Date,
starttime time,
endtime time,
memberid Integer,
courtid Integer,
fee Decimal(18,3),
Primary Key(id),
Foreign Key(MemberID) references Member(id),
Foreign Key(CourtID) references Court(id)
);
If I remove the foreign keys, the scaffold works. But... The foreign keys just are... not existing anymore.
(Here is the full SQL code, from the tutorial.
drop database if exists tennisClub;
create database tennisClub;
use tennisClub;
Create table Member(
id integer auto_increment,
firstname Varchar(30),
surname Varchar(30),
membertype Varchar(6),
dateofbirth date,
Primary Key(id)
);
Create table Court
(
id integer auto_increment,
surface varchar(30),
floodlights boolean,
indoor boolean,
Primary Key(id)
);
Create Table Booking
(
id integer auto_increment,
bookingdate Date,
starttime time,
endtime time,
memberid Integer,
courtid Integer,
fee Decimal(18,3),
Primary Key(id),
Foreign Key(MemberID) references Member(id),
Foreign Key(CourtID) references Court(id)
);
INSERT INTO Member (Firstname,Surname,MemberType,DateOfBirth) VALUES ('Oliver','Kerr','Senior','2000-01-31');
INSERT INTO Member (Firstname,Surname,MemberType,DateOfBirth) VALUES ('Morgan','Bartlett','Senior','1985-10-28');
INSERT INTO Member (Firstname,Surname,MemberType,DateOfBirth) VALUES ('Rebecca','House','Senior','1993-08-01');
INSERT INTO Member (Firstname,Surname,MemberType,DateOfBirth) VALUES ('Leslie','Hammond','Senior','1999-03-03');
INSERT INTO Member (Firstname,Surname,MemberType,DateOfBirth) VALUES ('Axel','Gibson','Senior','2007-09-29');
INSERT INTO Member (Firstname,Surname,MemberType,DateOfBirth) VALUES ('Bo','Bradshaw','Senior','1979-12-19');
Insert into Court(Surface, Floodlights, Indoor) Values('Savannah',1,1);
Insert into Court(Surface, Floodlights, Indoor) Values('Grass',1,0);
Insert into Court(Surface, Floodlights, Indoor) Values('Savannah',1,1);
Insert into Court(Surface, Floodlights, Indoor) Values('Savannah',1,1);
Insert into Court(Surface, Floodlights, Indoor) Values('Grass',0,0);
Insert into Court(Surface, Floodlights, Indoor) Values('Grass',0,0);
INSERT INTO Booking (BookingDate,StartTime,EndTime,MemberID,CourtID,Fee) VALUES ('2017-01-07','09:00:00','11:00:00',2,3,10.00);
INSERT INTO Booking (BookingDate,StartTime,EndTime,MemberID,CourtID,Fee) VALUES ('2017-02-11','16:00:00','17:00:00',5,3,10.00);
INSERT INTO Booking (BookingDate,StartTime,EndTime,MemberID,CourtID,Fee) VALUES ('2016-11-16','10:00:00','12:00:00',4,2,20.00);
INSERT INTO Booking (BookingDate,StartTime,EndTime,MemberID,CourtID,Fee) VALUES ('2017-04-06','14:00:00','16:00:00',2,5,10.00);
INSERT INTO Booking (BookingDate,StartTime,EndTime,MemberID,CourtID,Fee) VALUES ('2017-01-17','17:00:00','18:00:00',5,6,10.00);
INSERT INTO Booking (BookingDate,StartTime,EndTime,MemberID,CourtID,Fee) VALUES ('2017-05-06','15:00:00','17:00:00',3,6,15.00);
INSERT INTO Booking (BookingDate,StartTime,EndTime,MemberID,CourtID,Fee) VALUES ('2017-04-27','09:00:00','11:00:00',2,3,10.00);
INSERT INTO Booking (BookingDate,StartTime,EndTime,MemberID,CourtID,Fee) VALUES ('2016-05-05','16:00:00','17:00:00',5,3,10.00);
INSERT INTO Booking (BookingDate,StartTime,EndTime,MemberID,CourtID,Fee) VALUES ('2017-03-23','10:00:00','12:00:00',4,2,20.00);
)
Details
- System info and versions (if possible): Environment: PHP Version: 7.1.6 PHP SAPI: cli PHP Bin: D:\Xampp\php\php.exe PHP Extension Dir: C:\php\ext PHP Bin Dir: C:\php Loaded PHP config: D:\Xampp\php\php.ini Versions: Phalcon DevTools Version: 3.4.0 Phalcon Version: 3.4.0 AdminLTE Version: 2.3.6
- Phalcon Framework version: (
php --ri phalcon) - PHP Version: (
php -v) - Operating System:
- Server: Apache
- Other related info (Database, table schema): MySQL database.
Thanks in advance.
I've had a look at this.
There seems to be a conflict somewhere in the code between the --namespace option and tables that have Foreign Keys referencing them.
The problem doesn't occur for tables that do not have Foreign Keys referencing them.
The problem does not occur if you introduce --namespace=""
i.e. phalcon scaffold member --get-set --namespace=""
- OS: Windows NT LPT-50017010 10.0 build 16299 (Windows 10) i586
- PHP Version: 7.1.4
- PHP SAPI: cli
- PHP Bin: c:\xampp\php\php.exe
- PHP Extension Dir: C:\php\ext
- PHP Bin Dir: C:\php
- Loaded PHP config: C:\xampp\php\php.ini
- Versions:
- Phalcon DevTools Version: 3.4
- Phalcon Version: 3.3.1
- AdminLTE Version: 2.3.6
Hi,
@eokenned the scaffold command doesn't have a "namespace" option.
@JeremySwiat you can use --ns-models="Store\Models" --ns-controllers="Store\Controllers", but first you need to set up the namespaces.
"If models have relationships they must include the namespace too"
This issue is caused by typo in Builder/Model.php
We should call $this->modelOptions->hasOption('namespace') instead of $this->modelOptions->getOption('namespace')
Fixed