Jump to content

leoric

Members
  • Posts

    39
  • Joined

  • Last visited

Posts posted by leoric

  1. Is there anybody trying to use Ajax and JSONP in PW?

    here is my code, but it does not working.  it looks like "$config->ajax" didn't work.

    Client:

    	$(function(){
    		$.ajax({
    				type: "GET",
    				async: false,
    				url: "http://localhost/processwire/",
    				dataType: 'jsonp',
    				jsonp: "callback",
    				jsonpCallback: "jsonpCallback",
    				success: function (data) {
    					$.each(data,function(i,val){
    						$("body").prepend(i + ' ' +val.fullName + ' ' + val.fullAdress + '<br>');
    					});		
    				},
    				 error: function(){
    					 alert('fail');
    				 }			
    		
    		});
    	});
    

    Server:

    if($config->ajax)
    {
    	$array = array(
    		 '0' => array('fullName' => 'Meni Samet', 'fullAdress' => 'New York, NY'),
    		 '1' => array('fullName' => 'Test 2', 'fullAdress' => 'Paris'),
    	);
    	if($input->get->callback)
    	{
    		header("Content-Type: application/json");
    		echo $input->get->callback."(".json_encode($array).")";
    	
    	}
    }
    else
    {
    	include("./basic-page.php");
    }
    
  2. Hi @leoric,

    I assume the error occures on the imagefield named watermark as you can use the pimLoad method with the field named images.

    Here are a few questions:

    • Does your template / page have an imagefield with (exactly) that name?
    • Is this imagefield set to accept only a single image?

    big help.

    @horst, thank you!

  3. hi  @horst  :

    i want to add a watermark for page image. and use this module then got an error:

    Error: Call to a member function pimLoad() on a non-object 

    this caused error:

     
    $img = $page->images->first();
    
    $wmi = $page->watermark->pimLoad('wmi')->colorize('red')->pimSave();
    
    $imgsrc = $img->pimLoad('tw',true)->width(180)->grayscale()->watermarkLogo($wmi, 'southeast', 0)->pimSave();
    
    echo "<img src='{$imgsrc->url}' /><br />";
    
     

    i use this,its works well, i found the new image be created:

    $img = $page->images->first();
    $imgsrc = $img->pimLoad('myPrefix')->setOptions($options)->width(300)->pimSave();
    echo "<img src='{$imgsrc->url}' /><br />";
    
  4. i have a repeater field  named 'q_items'.

    the repeater 'q_items' have a PageArray field named 'products'.

    and now i want search by products field's title.

    //category A ---------------------------------------------------------------------

    Page A:

    ----title

    ----q_items

    --------products = PageD  (the page's title contain 'processwire',PageA will be show in the search result)

    Page B:

    ----title

    ----q_items

    --------products = PageE 

    Page C:

    ----title

    ----q_items

    --------products = PageF  (the page's title contain 'processwire',PageC will be show in the search result)

    //category B ----------------------------------------------------------------

    Page D

    ----title = "i love processwire"

    ----body

    Page E

    ----title= "i love this world"

    ----body

    Page F

    ----title= "hello,processwire"

    ----body

    in the sample data, when i search 'processwire' and  will get PageA and PageC

    this is an error expression:

    $matches=$pages->find(q_items.products.title%=processwire)

    is it possible to do this?

     
  5. Are you using repeaters in the template for the page you are trying to add? Or is this just at the stage where you enter a page title before going to the main page editing form?

    hi, pete thank you for your reply.

    finally i found the cause of this problem. this code spent too much time to execute..

    $id=$this->pages->find("include=all")->last()->id+1;
    

    Is there a way to replace this?  here is full code in the module:

    	public function hookRender(HookEvent $event) {
    	  if($this->process != 'ProcessPageAdd') return;
    	  $id=$this->pages->find("include=all")->last()->id+1;  //get the latest id
    	  $inputfield = $event->object;
    	  if(strlen($inputfield->attr('value'))) return; 
    	  $inputfield->attr('value', $id);  
    	}
    
  6. hi,everyone:

    i have a problem.

    there are currently 1700 pages in my site (it have a continual  trend of increases...)

    and now the problem is :   create a new page need a long time , more than 15 seconds. whether via api or back end.

    the details(such as in the back end page tree create new page, any parent):

    when i click "new" then i have to waiting for more than  15 seconds ...  after a long waiting i will see " add new " page form.( title, name and template select..)

     what is the problem?

  7. hi,ryan

    i found a issue after my test( PW 2.4)

    when i unstalled the module i still could found permissions in this page(i could checked the checkbox and saved):

    Access -> Roles -> Role Name -> edit

    it's looks like no uninstall clean.at last i had to deleted them in this page:

    Access -> Permissions

    is this a bug?

  8. hi,everybody:

    I solved the problem.

    its my fault,i cant describe the question clearly. but the forum is very helpful,at last i found the solution in forum.

    here is my test code:

    $q='keyword';
    $matches = $pages->find("title|summary|%=$q,template=_page_show");
    $uniqueResults = array(); 
    foreach($matches as $child)
    {
    	//echo $child->title.'<br>';
            //get the result page's parents
    	$uniqueResults[$child->parent->title]=$child->parent;
    }
    
    foreach($uniqueResults as $r)
    {
    	echo '<b><a href="'.$r->url.'">'.$r->title.'</a></b><br>';
    }
    

    this post is helpful to me.

    http://processwire.com/talk/topic/2038-distinct-selector-in-processwire/?p=19058

    thank you all!

    • Like 2
  9. I read your question three times and still don't understand it, might be that someone else will read it more clearly and will be able to help you, but in case it's not just me having trouble with it, can you give some concrete examples of what you want to achieve?

    diogo , i am so sorry,my english is not good.  

    i want to do this:

    here is  some goods in my database(such as clothes):

    (default search result) when i input a keyword like "Shirts",we will get all the results of the search criteria (categories:men's shirts,women's shirts,boy's chirts...etc..)

    and now,i want to add a navigation bar on the top of search result for better filter goods.

    there are some categories in the navigation bar ( men's shirts, women's shirts......),when i click men's shirts then we can get all men's shirts in the result.

    is this more clear?

  10. this topic is unclear.

    you can go to 3 and 7  floor , thank you.

    i have a query result

    $matches = $pages->find("title|summary|%=$q,template=_page_show,limit=12"); 
    

    and i have a demand: find these result pages parent, then i could second search by page's parent(through click parent link and urlSegment)

    it's means:

    page tree:

            category A

                    some pages..

            category B

                    some pages..

            category C

                    some pages..

            category D

                    some pages..

    search result:

    all categories    category A  category B .....(if the category have search result)

    some pages from search..

    some pages from search..

    some pages from search..

    the default search result is all categories

    $matches = $pages->find("title|summary|%=$q,template=_page_show,limit=12"); 
    

    when i click category A, we could get category id by urlSegment do this query 

    $matches = $pages->find("title|summary|%=$q,parent_id=$parent_id,template=_page_show,limit=12"); 
    

    ui example:

    all categories    category A  category B .....

    some pages from search..(category A's Child)

    some pages from search..(category A's Child)

    some pages from search..(category A's Child)

    ...

    now my question is  how to get all search result pages parents?  :(

    is there anyone have solution? thank you.

  11. Another approach would be to have a duplicate of your template folder where you use diffferent code inside your templates. I use this a lot for development in a live site, but its an easy solution to use it for a mobile website too.

    When your normal site is finished (or while developing) make a duplicate of the template folder and name it "templates-mobile". The goal here is to have exactly the same template files in both folders.

    Paste the following code at the bottom of the /site/config.php file and change the m.domain.ext to your needs

    if($_SERVER['HTTP_HOST'] == 'm.domain.ext') {
        $config->urls->templates = '/site/templates-mobile/';
        $config->paths->templates = $rootPath . $config->urls->templates;
    }
    

    This way when you visit your website on m.domain.ext it will use the templates out of the templates-mobile folder while it still uses the same data from the database, assets folder and the modules.

    Raymond Geerts,you are a great help.  thank you!

    • Like 1
  12. While that's one way of dealing with a mobile site, the other way would be to use a mobile-first front end framework (such as Bootstrap 3 or Zurb Foundation 4/5) and develop your site at your abc.com domain.

    I would be very interested to know why Baidu thinks (for SEO purposes)  that the separate mobile site is better than a consolidated website (mobile and responsive) at the same domain.

    hi, cstevensjr and Marty Walker

    thank you for your reply

    i have been think so before,i even think its unreasonable. but in the fact it done.  

    baidu highly recommended webmaster build mobile website. and them made a tool to online building mobile site (siteapp.baidu.com)

    unfortunately our chinese language website have a large proportion of traffic from baidu search. so we have to  comply with official seo suggestion.

    i think baidu have two independent systems(pc and mobile).

    i do this if there have a good solution.

  13. Glad to help.

    Just one thing - from what you describe, it sounds like you are editing the core ProcessPageAdd module. You don't want to do this, because you'll have to make these changes again every time you upgrade PW. Instead you should create your own simple module using that code.

    Read here for a tutorial on creating your own module:

    http://wiki.processwire.com/index.php/Module_Creation

    wow, it's so cool.......i'm very  very happy...

    yes,i did it.

    this is my first time to make a module.  

    thank you very much,adrian .

    • Like 2
  14. thank you,adrian  , your reply is very helpful.. 

    and thanks for ryan  in here:

    http://processwire.com/talk/topic/1908-automatically-generating-new-page-names/?p=17887

    i do this and get what i want:

    open "wire\modules\process\ProcessPageAdd\ProcessPageAdd.module":

    find this : "public function init()"  and add this line 

    $this->addHookBefore('InputfieldPageName::render', $this, 'hookRender'); 
    

    then add this function in this class:

    	public function hookRender(HookEvent $event) {
    	  if($this->process != 'ProcessPageAdd') return;
    	  $id=$this->pages->find("include=all")->last()->id+1;  //get the latest id
    	  $inputfield = $event->object;
    	  if(strlen($inputfield->attr('value'))) return; 
    	  $inputfield->attr('value', $id);  
    	}
    

    ok,that's all.

    thank you everyone!

  15. name*
    Any combination of letters (a-z), numbers (0-9), dashes or underscores (no spaces).

    i use chinese language, i have to translated page title to english every time.

    its a problem for me  :(

    if it could be this?

    when i dont type anything in this option system automatic insert the id(the last page id +1 )

    is there have some solutions?

    thank you.

  16. welcome be PWer!  

    config admin URL:

    as admin login backend : page tree -> admin -> edit -> setting -> name -> save

    ---------------------------------------------------------------------------------------------------------------------

    add a  template:

    go to document directory  -> /site/templates/ 

    add a new  template file   "demo.php" ( some content....)

    go to  admin backend :  setup -> templates -> add new templates  ( the system will find "demo.php") ->  checked  -> add templates

    then go back , in "setup->templates" you can see "demo.php" , click "demo.php" in templates list, then you can manage fields for this template.

    how to use?

    page -> edit -> setting -> template -> in the templates list you can see " demo "

    ---------------------------------------------------------------------------------------------------------------------

    these modules are  helpful for you.

    http://modules.processwire.com/modules/

    trust me , PW is a good choice.

    in the fact,pw not only as a cms, more like a framework, if you are a phper , you will love it even more ...

    my english comprehension limit.  if this helpful?

  17. I just looked into this again and there's no argument for removeAll() just for remove($key). 

    See here in source https://github.com/ryancramerdesign/ProcessWire/blob/dev/wire/core/WireArray.php#L790

    removeAll() removes ALL pages from a Wire/PageArray (pages, images, POST vars etc). So I'm not sure about why it works for you because it shouldn't and also doesn't work for me.

    Assuming user_app is a page field allowing multiple pages to be selected. It's a WireArray/PageArray and you add pages to it like this from API:

    $user->of(false);
    $page1 = $pages->get("/somepage/");
    $page2 = $pages->get("/someotherpage/");
    $user->user_app->add($page1);
    $user->user_app->add($page2);
    $user->save();
     

    Now we got 2 pages added to the page field.

    If you now do a $page->user_app->removeAll($page1) they all get removed so does $user->user_app->removeAll();

    But if you do:

    $page2 = $pages->get("/someotherpage/");
    $user->user_app->remove($page2);
    $user->of(false);
    $user->save();
     

    Now only the $page2 which is in the array gets removed. It works all as expected and make sense.  :rolleyes:

    @soma ,your reply is very helpful...

    my fault: $app is a page id variable, not a $page object.

    $removepage = $pages->get($app);          ->  add this line
    $user->user_app->remove($removepage);   ->change removeall  to remove   
     
    its working ^-^
     

    thank you very much!

    • Like 1
×
×
  • Create New...