landitus Posted October 17, 2011 Share Posted October 17, 2011 Hi all! Today I am curious about the following. I have a rather large Codeigniter site and suddenly I'm in need of a CMS for 2 o 3 sections of the site. I really like PW and It's so easy to use I wouldn't dare to try and build something in Codeigniter for the little backend / CMS. So I read the bootstrap section and tryied to code the integration but I can't get it to work. I've put PW inside a pw folder in my root directory. When you enter the site, the CI bootstrap index.php file is called. I was able to include the PW index.php file into the CI bootstrap index.php file. But when I try to call a simple PW function from CI, I don't see anything: <?php $mypage = wire("pages")->get("/about/"); ?> It actually breaks the site, but don't see any errors. Just a lot of white space. Debug is "ON" on both systems. Would you recommend my approach? Am I going to regret this? thanks! Link to comment Share on other sites More sharing options...
apeisa Posted October 17, 2011 Share Posted October 17, 2011 Do you want to run PW from subdirectory? Like www.domain.com serves your CI application, but www.domain.com/cms/ would be ProcessWire? If that is the case, then I wouldn't go bootstrapping at all, I would just install the pw in to the subdir. I'm not sure but you might need to change something in CI .htaccess to allow that. PW is fine to install into the subdir though. If you need to access PW API from CI application, then you would need to include pw at some point of your app. Might require small wrapper file, but probably not (what I remember when I worked with CI, it does stay out of the way most of the time). Link to comment Share on other sites More sharing options...
landitus Posted October 17, 2011 Author Share Posted October 17, 2011 Thanks for the reply! Do you want to run PW from subdirectory? Like www.domain.com serves your CI application, but www.domain.com/cms/ would be ProcessWire? If that is the case, then I wouldn't go bootstrapping at all, I would just install the pw in to the subdir. I'm not sure but you might need to change something in CI .htaccess to allow that. PW is fine to install into the subdir though. This is the case. If you need to access PW API from CI application, then you would need to include pw at some point of your app. Might require small wrapper file, but probably not (what I remember when I worked with CI, it does stay out of the way most of the time). I really need to access PW API from CI. So I figured that including PW in the CI index.php file: CI index.php in the root: include('./pw/index.php'); This way, the app runs fine. No errors. But when I add this inside a CI view file: <?php $mypage = wire("pages")->get(1001) ;?> everything breaks... Hope this fills some blanks of what I'm trying to do. Link to comment Share on other sites More sharing options...
apeisa Posted October 17, 2011 Share Posted October 17, 2011 Hmm.. I am pretty sure that including at the index.php is not the best way to do it. Which version of CI are you using? 2.0+ or 1.xx? I am heading to bed now, but will look for this topic - probably helpful for many. Link to comment Share on other sites More sharing options...
landitus Posted October 17, 2011 Author Share Posted October 17, 2011 I'm using PW 2.1 and CI 2.0.1 Thanks for your help! I hope it's useful to all. Link to comment Share on other sites More sharing options...
Adam Kiss Posted October 18, 2011 Share Posted October 18, 2011 I'm just thinking out loud, but wouldn't the best approach be to create small CI wrapper – probably model (since we're accessing data here, albeit via API), and access wire() throught that model? Something like <?php function __construct(){ $this->pages = wire('pages'); } $this->pw->pages->find('...'); As for white page, I'm 99% sure there's some PHP error along the way; have you checked php_error.log, whether it's not some dumb missing semicolon? Link to comment Share on other sites More sharing options...
landitus Posted October 21, 2011 Author Share Posted October 21, 2011 Hey! I think I'm way over my head here, cause I'm getting a "Fatal error: Call to undefined function wire()" error... seems I am not even including the bootstrap right. Isn't it? Link to comment Share on other sites More sharing options...
ryan Posted October 21, 2011 Share Posted October 21, 2011 PW still needs to support the PHP 5.2 branch, so we're not using namespaces yet, and I don't think that CI is either. As a result, I'm betting there's at least a chance that PW and CI would have a namespace conflict. include('./pw/index.php'); It's possible that CI may chdir somewhere else, so just as a test, you may want to put in an absolute path to PW. Given that the wire() function apparently isn't even defined, it makes me think that PW hasn't even had a chance to load yet. Link to comment Share on other sites More sharing options...
Soma Posted October 21, 2011 Share Posted October 21, 2011 CI index.php ... include("./pw/index.php"); require_once BASEPATH.'core/CodeIgniter.php'; it works fine. latest CI and PW in a subdirectory /pw ... i can in welcome_message.php output pw pages... I just tried because I also plan to use both for a project. Great possibilities! <?php // in CI view files... $pa = wire("pages")->get('/')->children(); foreach($pa as $child){ echo $child->title."<br/>"; } Edit: You can even use it in controllers, or use the render method to output whole page markup. Though depending on the setup and paths this doesn't load images or css/js but maybe a htaccess could fix this. Not sure yet how far you can combine these two frameworks, but doing well so far. <?php $pa = wire('pages')->get("/about/"); $pa->setOutputFormatting(true); echo $pa->render(); Edit: You can also include PW index.php using a CI processwire_helper.php and autoload it. So wire is available in all view and controllers. Link to comment Share on other sites More sharing options...
landitus Posted December 29, 2011 Author Share Posted December 29, 2011 I've just read your message Soma! :-\ I'm going to try your approach ASAP . Did you find any roadblocks so far? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now