colap Posted July 7, 2015 Share Posted July 7, 2015 use Cake\ORM\Table; What i have understand: Load Cake folder>then ORM folder>then Table.php Is that correct ? Quote Link to comment https://forums.phpfreaks.com/topic/297203-what-this-line-do/ Share on other sites More sharing options...
requinix Posted July 7, 2015 Share Posted July 7, 2015 Almost. There is a class somewhere named "Table" in the "Cake\ORM" namespace. Odds are it will be in a file Cake\ORM\Table.php (or .class.php or whatever) but that is not always true. Normally to refer to that class in code you would have to write the full path, like $table = new \Cake\ORM\Table();With a use you can tell PHP that any mention of "Table" actually refers to Cake\ORM\Table, so you can write the shorter $table = new Table(); Quote Link to comment https://forums.phpfreaks.com/topic/297203-what-this-line-do/#findComment-1515741 Share on other sites More sharing options...
colap Posted July 8, 2015 Author Share Posted July 8, 2015 Almost. There is a class somewhere named "Table" in the "Cake\ORM" namespace. Odds are it will be in a file Cake\ORM\Table.php (or .class.php or whatever) but that is not always true. Normally to refer to that class in code you would have to write the full path, like $table = new \Cake\ORM\Table();With a use you can tell PHP that any mention of "Table" actually refers to Cake\ORM\Table, so you can write the shorter $table = new Table(); arent Cake and ORM folders? Quote Link to comment https://forums.phpfreaks.com/topic/297203-what-this-line-do/#findComment-1515811 Share on other sites More sharing options...
maxxd Posted July 8, 2015 Share Posted July 8, 2015 They may be folders, but in this case you're dealing with namespaces, not folder structure. Assuming everything in Cake is using an autoloader, I would expect to find the namespaces correspond with the directory structure, but it certainly doesn't have to. Quote Link to comment https://forums.phpfreaks.com/topic/297203-what-this-line-do/#findComment-1515817 Share on other sites More sharing options...
scootstah Posted July 8, 2015 Share Posted July 8, 2015 Almost. There is a class somewhere named "Table" in the "Cake\ORM" namespace. Odds are it will be in a file Cake\ORM\Table.php (or .class.php or whatever) but that is not always true. Normally to refer to that class in code you would have to write the full path, like $table = new \Cake\ORM\Table();With a use you can tell PHP that any mention of "Table" actually refers to Cake\ORM\Table, so you can write the shorter $table = new Table(); arent Cake and ORM folders? They may be folders in this case, but namespaces do not have to have a matching directory structure. In order to follow the PSR-0 standard, namespaces do have to have a matching directory structure. I'm not sure if CakePHP follows PSR-0 or not. Quote Link to comment https://forums.phpfreaks.com/topic/297203-what-this-line-do/#findComment-1515818 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.